其实还是蛮复杂的。
看图

晚上下班的时候,天灰蒙蒙的,小车掠过潮湿的路面,冷风迎面而来,微微有些寒意,在这寒意中,想起了我的小舅。
小舅在我的印象里,永远是精神抖擞的,他带着还不怎么懂事的我去上班,工作的时候让我在旁边玩耍。我不知道自己为什么去那里,也不知道他为什么工作那么辛苦,还要带着一个不能帮忙的孩子过去,但是那个情景一直印在我的脑子里,直到今天都丝毫没有磨灭,我始终记得我曾经好奇地透过一扇窗,看着他在那里忙碌,只是,那扇窗我再也找不着了。
他忙完之后,带着我去动物园玩。那是我第一次去动物园,我们在那里捡到了一根孔雀的羽毛,颜色绚丽,五彩斑斓,回去的路上,我一直攥在手中,高兴了一路。
后来我上大学,我们没有见过面。
研究生放暑假的时候,我在家里,半夜接到了一个电话,当时有些迷迷糊糊,听着电话里男人的声音,无论我怎么问,他都不说是谁,只是说着很多喜欢我的词,唉,除了这个小舅还能是谁呢。
他是一个要强的人,一个为了家庭不断努力的人。
他是一个真诚的人,一个不懂得隐饰自己感情的人。
他对别人总是尽心尽力,惟独忘了照顾好他自己。
就在上个月小舅不幸因病辞世,我去看他了,充满了懊恼,一句话都不能说。
一个鲜活的生命,就这样从这个世界消失了,许多感谢的话都已经无从说起,很多年前没有懂的,现在似乎懂了。
在这个深夜里写下对小舅的回忆,寄托哀思,愿你在天堂安好!

Django源码阅读

每次都要跟别人解释python三大WEB框架,这次总算凑齐了。
搞应用其实都差不多,框架却是各显神通,设计模式很重要。

Android应用设计

看完两套代码,感觉一个办公室的人,技术上基本快隔代了。
前端发展得快,从技术上说,更容易淘汰一批跟不上的人员。

愿景

希望找到一个真正能发挥技术实力的地方。

必要知识

oriole-service ≥ 30.6.0

还不会创建微服务?看

环境

为了演示,创建三个微服务:

  • eric_service 独立服务
  • src_service 起始服务,使用中间服务进行审核,然后继续执行。
  • mid_service 中间服务

简略表示为: 【src_service】->【mid_service】->【src_service】
三个微服务处于同一个容器中,实际上如果分别运行在不同的容器中,结果与本文完全一致,这正是分布式的强大之处。
微服务同时运行,交错输出,不是传统的A调用B结束之后B再调用A,以后有机会再细说其中奥妙。

默认方法

采用oriole_service创建的所有微服务自动加入跟踪,如下图:

1
2
3
4
微服务跟踪显示三个服务都参与了服务自动发现
[eric_service.ms_update_service.301fa437-5e46-4d39-b116-6b3ad2b8c84a] entrypoint result trace
[mid_service.ms_update_service.bc1a29e8-8a20-44e1-96fa-e14b3d5acd18] entrypoint call trace
[src_service.ms_update_service.cb07d701-e74a-4842-bcac-cb65a981a760] entrypoint call trace

高级方法

显示详细信息

在services.cfg中加入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
LOGGING:
version: 1
disable_existing_loggers: false
formatters:
tracer:
(): nameko_tracer.formatters.JSONFormatter
loggers:
nameko_tracer:
level: INFO
handlers: [tracer]
handlers:
tracer:
class: logging.StreamHandler
formatter: tracer

执行o s

1
2
3
4
5
6
7
8
显示所有在线服务
服务名 容器 版本
eric_service => 73273e056d25|1.0.1
mid_service => 73273e056d25|0.0.1
src_service => 73273e056d25|0.0.1

调用src_service微服务的add方法
>>> src_service.add()

输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[src_service.add.f1fcca92-d5a7-4d78-9237-dc50f40ef71d] entrypoint call trace

{
"hostname": "73273e056d25",
"service": "mid_service",
"context_data": {},
"call_id": "mid_service.handle.9bc76133-7302-4771-8248-460a870b5082",
"call_id_stack": [
"standalone_rpc_proxy.call.b0c00628-0d5e-47f5-89f0-ddc0aa6c709d",
"src_service.add.f1fcca92-d5a7-4d78-9237-dc50f40ef71d",
"mid_service.handle.9bc76133-7302-4771-8248-460a870b5082"
],
"origin_call_id": "standalone_rpc_proxy.call.b0c00628-0d5e-47f5-89f0-ddc0aa6c709d",
"stage": "request",
"call_args": {"params": {"param": "eric"}},
"call_args_redacted": false
}

[mid_service.handle.9bc76133-7302-4771-8248-460a870b5082] entrypoint call trace

后记

软件设计形同对弈,鼠目寸光则困于当下,势利均沾方可进退自如,世所困扰大体如是。

写代码的时候,要有基本的语言常识,比如Python,你就不能忽视语言本身的特点随便乱写。
20万次递归的结果:

纯Python代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,
621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,
643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,
665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,
687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,
709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,
731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,
753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,
775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,
797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,
819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,
841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,
863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,
885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,
907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,
929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,
951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,
973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,
995,Traceback (most recent call last):
File "./tt.py", line 3, in <module>
cur(0, 200000)
File "test.py", line 12, in t.cur
File "test.py", line 12, in t.cur
File "test.py", line 12, in t.cur
[Previous line repeated 993 more times]
File "test.py", line 6, in t.cur
RecursionError: maximum recursion depth exceeded while getting the str of an object

最大996 :)

Python动态库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
174133,174134,174135,174136,174137,174138,174139,174140,174141,174142,174143,174144,174145,
174146,174147,174148,174149,174150,174151,174152,174153,174154,174155,174156,174157,174158,
174159,174160,174161,174162,174163,174164,174165,174166,174167,174168,174169,174170,174171,
174172,174173,174174,174175,174176,174177,174178,174179,174180,174181,174182,174183,174184,
174185,174186,174187,174188,174189,174190,174191,174192,174193,174194,174195,174196,174197,
174198,174199,174200,174201,174202,174203,174204,174205,174206,174207,174208,174209,174210,
174211,174212,174213,174214,174215,174216,174217,174218,174219,174220,174221,174222,174223,
174224,174225,174226,174227,174228,174229,174230,174231,174232,174233,174234,174235,174236,
174237,174238,174239,174240,174241,174242,174243,174244,174245,174246,174247,174248,174249,
174250,174251,174252,174253,174254,174255,174256,174257,174258,174259,174260,174261,174262,
174263,174264,174265,174266,174267,174268,174269,174270,174271,174272,174273,174274,174275,
174276,174277,174278,174279,174280,174281,174282,174283,174284,174285,174286,174287,174288,
174289,174290,174291,174292,174293,174294,174295,174296,174297,174298,174299,174300,174301,
174302,174303,174304,174305,174306,174307,174308,174309,174310,174311,174312,174313,174314,
174315,174316,174317,174318,174319,174320,174321,174322,174323,174324,174325,174326,174327,
174328,174329,174330,174331,174332,174333,174334,174335,174336,174337,174338,174339,174340,
174341,174342,174343,174344,174345,174346,174347,174348,174349,174350,174351,174352,174353,
174354,174355,174356,174357,174358,174359,174360,174361,174362,174363,174364,174365,174366,
174367,174368,174369,174370,174371,174372,174373,174374,174375,174376,174377,174378,174379,
174380,174381,174382,174383,174384,174385,174386,174387,174388,174389,174390,174391,174392,
174393,174394,174395,174396,174397,174398,174399,174400,174401,174402,174403,174404,174405,
174406,174407,174408,174409,174410,174411,174412,174413,174414,174415,174416,174417,174418,
174419,174420,174421,174422,174423,174424,174425,174426,174427,174428,174429,174430,174431,
174432,174433,174434,174435,174436,174437,174438,174439,174440,174441,174442,174443,174444,
174445,1744fish: “python ./t.py” terminated by signal SIGSEGV (Address boundary error)

最大174447

Python的C模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
199593,199594,199595,199596,199597,199598,199599,199600,199601,199602,199603,199604,199605,
199606,199607,199608,199609,199610,199611,199612,199613,199614,199615,199616,199617,199618,
199619,199620,199621,199622,199623,199624,199625,199626,199627,199628,199629,199630,199631,
199632,199633,199634,199635,199636,199637,199638,199639,199640,199641,199642,199643,199644,
199645,199646,199647,199648,199649,199650,199651,199652,199653,199654,199655,199656,199657,
199658,199659,199660,199661,199662,199663,199664,199665,199666,199667,199668,199669,199670,
199671,199672,199673,199674,199675,199676,199677,199678,199679,199680,199681,199682,199683,
199684,199685,199686,199687,199688,199689,199690,199691,199692,199693,199694,199695,199696,
199697,199698,199699,199700,199701,199702,199703,199704,199705,199706,199707,199708,199709,
199710,199711,199712,199713,199714,199715,199716,199717,199718,199719,199720,199721,199722,
199723,199724,199725,199726,199727,199728,199729,199730,199731,199732,199733,199734,199735,
199736,199737,199738,199739,199740,199741,199742,199743,199744,199745,199746,199747,199748,
199749,199750,199751,199752,199753,199754,199755,199756,199757,199758,199759,199760,199761,
199762,199763,199764,199765,199766,199767,199768,199769,199770,199771,199772,199773,199774,
199775,199776,199777,199778,199779,199780,199781,199782,199783,199784,199785,199786,199787,
199788,199789,199790,199791,199792,199793,199794,199795,199796,199797,199798,199799,199800,
199801,199802,199803,199804,199805,199806,199807,199808,199809,199810,199811,199812,199813,
199814,199815,199816,199817,199818,199819,199820,199821,199822,199823,199824,199825,199826,
199827,199828,199829,199830,199831,199832,199833,199834,199835,199836,199837,199838,199839,
199840,199841,199842,199843,199844,199845,199846,199847,199848,199849,199850,199851,199852,
199853,199854,199855,199856,199857,199858,199859,199860,199861,199862,199863,199864,199865,
199866,199867,199868,199869,199870,199871,199872,199873,199874,199875,199876,199877,199878,
199879,199880,199881,199882,199883,199884,199885,199886,199887,199888,199889,199890,199891,
199892,199893,199894,199895,199896,199897,199898,199899,199900,199901,199902,199903,199904,
199905,199906,199907,199908,199909,199910,199911,199912,199913,199914,199915,199916,199917,
199918,199919,199920,199921,199922,199923,199924,199925,199926,199927,199928,199929,199930,
199931,199932,199933,199934,199935,199936,199937,199938,199939,199940,199941,199942,199943,
199944,199945,199946,199947,199948,199949,199950,199951,199952,199953,199954,199955,199956,
199957,199958,199959,199960,199961,199962,199963,199964,199965,199966,199967,199968,199969,
199970,199971,199972,199973,199974,199975,199976,199977,199978,199979,199980,199981,199982,
199983,199984,199985,199986,199987,199988,199989,199990,199991,199992,199993,199994,199995,
199996,199997,199998,199999,200000

完美的递归。

ORIOLE哲学

软件之道,唯快不破

设计目的

运用技术手段打造软件平台、提升研发效率,快速使用数据库、缓存、消息队列,强化整体代码风格。
oriole-service == dubbo | spring cloud, 如果没有软件平台,不必考虑本框架,杀鸡焉用牛刀。

准备工作

  1. 安装软件

注意:这些软件缺一不可,使用apt-get即可完成全部安装,实际开发会统一安装。

  • mongodb
  • mysql
  • rabbitmq
  • redis
  • python3.6
  1. 安装oriole-service

oriole-service是实现微服务的核心框架,实现了服务容器、测试、文档的自动化。

pip install oriole-service

配置 services.cfg

可以手工编辑,亦可使用o c统一配置。

1
2
3
4
AMQP_URI:      pyamqp://test:test@127.0.0.1
database: mysql://test:test@127.0.0.1/test?charset=utf8
test_database: mysql://test:test@127.0.0.1/test?charset=utf8
datasets: redis://127.0.0.1

编写服务 services/log.py

服务的简化版,编写完成后启动,可以使用o s远程调用。

1
2
3
4
5
6
7
8
9
10
from oriole_service.app import *

class LogService(App):
name = service_name(__file__)
ver = "1.0.0"

@rpc
def add(self, params={"param": "eric"}):
self.log.debug("# %s(%s)" % ("add", params))
return self._o(params)

运行服务

使用o r

o r log

运行客户端

o s

进入后,使用log_service.add()
该命令类似于dubbo的客户端和控制台。

自动创建文档

o d

创建镜像

如果没有docker经验,跳过本节。
每个微服务可以方便、快速地部署到docker、k8s中,不是本文要点,暂且不表。

o b log

声明

本软件可以自由使用,但是作者不对使用本软件出现的任何损失承担责任。
如有问题,请确保使用的是最新版本
如提PR,请注意代码风格与框架要保持完全一致,务必精简,否则不予接受。

完整的软件列表,用于故障检查和恢复。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
alabaster==0.7.12
amqp==2.4.2
Babel==2.5.3
certifi==2019.3.9
chardet==3.0.4
dnspython==1.16.0
docutils==0.14
eventlet==0.24.1
greenlet==0.4.15
idna==2.8
imagesize==1.1.0
importlib-metadata==0.9
Jinja2==2.10
kombu==4.5.0
MarkupSafe==1.1.1
mock==2.0.0
mockredispy==2.9.3
mogo==0.4.0
mongomock==3.8.0
monotonic==1.5
mysqlclient==1.3.12
nameko==2.11.0
oriole==16.1.0
oriole-service==26.2.0
packaging==19.0
path.py==11.5.2
pbr==5.1.3
pkg-resources==0.0.0
py==1.8.0
pyetcd==1.8.0
Pygments==2.3.1
pymongo==3.7.2
PyMySQL==0.7.11
pyparsing==2.4.0
pytest==3.2.3
pytz==2019.1
PyYAML==5.1
redis==2.10.6
requests==2.21.0
sentinels==1.0.0
six==1.12.0
snowballstemmer==1.2.1
Sphinx==1.7.2
sphinxcontrib-websupport==1.1.0
SQLAlchemy==1.2.14
urllib3==1.24.1
vine==1.3.0
Werkzeug==0.15.2
wrapt==1.11.1
zipp==0.3.3

为学之道,在日积月累
冰冻三尺,岂一日之寒

  • K8S自定义扩展原理与编写
  • 系统原型技术设计与编写
  • 数据分片技术方案与实现
  • SQLALCHEMY代码跟踪
  • ANGULARJS代码阅读

为学之道,在日积月累
冰冻三尺,岂一日之寒

  • K8S自定义扩展原理与编写
  • 系统原型技术设计与编写
  • 数据分片技术方案与实现
  • SQLALCHEMY代码跟踪
  • ANGULARJS代码阅读
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×