<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>五四陈科学院-坚信科学，分享技术 &#187; 架构研究</title>
	<atom:link href="http://www.54chen.com/category/architecture/feed" rel="self" type="application/rss+xml" />
	<link>http://www.54chen.com</link>
	<description>PHP、JAVA、缓存、架构、经验、分享</description>
	<lastBuildDate>Sat, 11 Feb 2012 17:09:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>人肉解析riak_admin join</title>
		<link>http://www.54chen.com/_linux_/riak_admin-join.html</link>
		<comments>http://www.54chen.com/_linux_/riak_admin-join.html#comments</comments>
		<pubDate>Fri, 10 Feb 2012 12:21:03 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[riak]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/riak_admin-join.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>riak_admin只是一个bash脚本，当riak_admin join被执行时，都是在执行riak_kv_console join。 大概过程分析 riak_kv_console:join => %%入口 riak:Join(Node) => %% 真正执行 riak_core:join(Node) => %%去到riak_core riak_core_gossip:legacy_gossip() => %%通知检查是否是 legacy gossip， riak_core:standard_join(Node,Ring,false) => %%非rejoin 非legacy riak_core_gossip:send_ring(Node, node()) => %% 进入gossip模块发起ring请求 gen_server:cast({?MODULE, FromNode}, {send_ring_to, ToNode}) => %%广而告之 riak_core_gossip:handle_cast({send_ring_to, Node}, State) => %%收到 gen_server:cast({?MODULE, &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img04.taobaocdn.com/imgextra/i4/13078490/T2AT9jXolXXXXXXXXX_!!13078490.jpg" alt="riak" /><br />
riak_admin只是一个bash脚本，当riak_admin join被执行时，都是在执行riak_kv_console join。</p>
<p><strong>大概过程分析</strong><br />
riak_kv_console:join  =>  %%入口<br />
riak:Join(Node) => %% 真正执行<br />
	riak_core:join(Node) => %%去到riak_core<br />
		riak_core_gossip:legacy_gossip() => %%通知检查是否是 legacy gossip，<br />
	riak_core:standard_join(Node,Ring,false) =>  %%非rejoin 非legacy<br />
		riak_core_gossip:send_ring(Node, node()) =>  %% 进入gossip模块发起ring请求<br />
			gen_server:cast({?MODULE, FromNode}, {send_ring_to, ToNode}) => %%广而告之<br />
		riak_core_gossip:handle_cast({send_ring_to, Node}, State) => %%收到<br />
			gen_server:cast({?MODULE, Node}, {reconcile_ring, RingOut}) => %%告诉它们开始协调<br />
 		riak_core_gossip:handle_cast({reconcile_ring, RingIn}, State) => %%收到<br />
			riak_core_ring_manager:ring_trans(fun reconcile/2, [OtherRing]) => %%由一个协调函数传入到ring manager中去执行<br />
			riak_core_ring_manager:prune_write_notify_ring => %%搞定一个新的ring文件，通知所有的listener<br />
			riak_core_ring_events:ring_update(Ring) => %%通过event通知<br />
riak_core_ring_handler:handle_event({ring_update, Ring}, State) => %%接到event<br />
	riak_core_vnode_manager:ring_changed(Ring) => %%vnode_manager通知大家环修改了<br />
		riak_core_vnode_manager:trigger_ownership_handoff(?MODULE, {ring_changed, Ring}) =>%%接通知触发handoff<br />
			riak_core_vnode:trigger_handoff(Pid, TargetNode) => %%由vnode来干活<br />
				gen_fsm:send_all_state_event(VNode, {trigger_handoff, TargetNode}) => %%使用gen_fsm来通知vnode们<br />
			riak_core_vnode:maybe_handoff => %%准备开始导数据<br />
			riak_core_vnode:start_handoff => %%开始<br />
			riak_core_handoff_manager:add_outbound => %%发handoff<br />
			handle_call({add_outbound,Mod,Idx,Node,Pid},_From,State=#state{handoffs=HS}) => %%收到请求<br />
				riak_core_handoff_manager:send_handoff => %%发<br />
					riak_core_handoff_sender_sup:start_sender => %%启动sender  最终启动了 riak_core_vnode_master:sync_command直到同步结束。 </p>
<p><strong>riak_core_vnode:mark_handoff_complete</strong><br />
此代码生存在riak_core_vnode，而不是riak_core_vnode_manager，因为ring_trans是一个同步的call到ring manager的过程，block一个单独的vnode要比block整个vnode manager要好。block这个manager会影响所有的vnode。此代码对多个并行的vnode执行是安全<br />
的,因为靠单个 ring manager提供的同步化保证了拥有所有的环的变更经过 。</p>
<p><strong>riak_core_vnode:vnode_command</strong><br />
活动的vnode运行于三种状态中：正常、handoff、推进。<br />
在正常状态，vnode命令靠handle_command来传递。当一个handoff被触发，handoff_node被设置为目标节点，并且这个vnode被称做进入了handoff状态。<br />
在handoff状态，vnode命令依靠handle_handoff_command来传递。即使handoff程序是非block的（比如在riak_kv中没有使用async fold时），在handoff期间，一个vnode也会被block住（所以没有服务命令）。<br />
handoff状态之后，一个vnode会进入到推进状态。推进状态是新的gossip/membership代码的产物，并且legacy模式的节点里不会出现。推进状态代表了vnode已经传递自己数据到新节点的情况，但新的节点并未在环上列出当前节点的信息。这会出现是因为增加的vnode仍然在等handoff他们的数据给新的拥有者，或者只是因为环还汇聚在这个新节点之上。在推进状态，所有的vnode指令和coverage命令都会按过程推给新的拥有者。</p>
<p><strong><br />
riak_core_vnode:start_manager_event_timer</strong><br />
独有的vnode进程与vnode manager结合紧密。当vnode的事件触发，这个vnode必须确保这个事件被发送到vnode manager，这将会产生一个状态变化的决定，并且发回适当的信息给这个vnode。为了最大限度地减少阻塞，使用了异步的消息。vnode manager挂掉而丢失靠vnode发送的信息是可能的。因此，vnode周期性地重发事件消息，直到一个从vnode manager来的合适的消息被接收。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/riak_admin-join.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>服务接入层小结</title>
		<link>http://www.54chen.com/_linux_/access-layer.html</link>
		<comments>http://www.54chen.com/_linux_/access-layer.html#comments</comments>
		<pubDate>Wed, 18 Jan 2012 05:10:31 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[接入]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/access-layer.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>接入层 是指普通用户与核心业务逻辑中间的过程。现在常见的服务接入层，像nginx、lvs、php这些都可以算是。 观点 一种观点认为：接入的量不应该影响系统的正常运行，也就是不能接入不能处理的用户请求，类似上图中前图。 另一种观点认为：接入层应该尽量接入所有用户，类似上图中后图。 做法 nginx： nginx如果用做proxy，后端挂其他服务的话，是一个纯粹的NIO server。对用户来说，nginx是长连接（http 1.1），对后端服务来说，nginx是短连接（http 1.0）。 default: proxy_connect_timeout 60s; 向后端服务创建连接的超时时间 default: proxy_read_timeout 60s; 后端返回请求响应超时时间 default: proxy_send_timeout 60s; 大请求发到后端超时时间 nginx通过上面的三个设置，当后端有响应不过来的时候，进行超时处理（记录日志），当发现超时很多了，就需要提升后端的处理能力了。 那么，nginx自身的处理能力是否有上限呢？当然有! worker_processes 1; worker_connections 1024; max_clients = worker_processes * worker_connections 当超过max_clients的用户扑上来的时候，如果幸运后端没有能力问题，那就会看到nginx在日志中要求你增加worker的提示。 php-fpm： pm = dynamic/static; dynamic时有最大进程最小进程之说，static时没有。只有一个上限。 &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img04.taobaocdn.com/imgextra/i4/13078490/T2evmjXahaXXXXXXXX_!!13078490.jpg" alt="access,layer" width=500/><br />
<strong>接入层</strong><br />
是指普通用户与核心业务逻辑中间的过程。现在常见的服务接入层，像nginx、lvs、php这些都可以算是。</p>
<p><strong>观点</strong><br />
一种观点认为：接入的量不应该影响系统的正常运行，也就是不能接入不能处理的用户请求，类似上图中前图。<br />
另一种观点认为：接入层应该尽量接入所有用户，类似上图中后图。</p>
<p><strong>做法</strong><br />
nginx：<br />
nginx如果用做proxy，后端挂其他服务的话，是一个纯粹的NIO server。对用户来说，nginx是长连接（http 1.1），对后端服务来说，nginx是短连接（http 1.0）。</p>
<blockquote><p>default: proxy_connect_timeout 60s; 向后端服务创建连接的超时时间<br />
default: proxy_read_timeout 60s; 后端返回请求响应超时时间<br />
default: proxy_send_timeout 60s; 大请求发到后端超时时间</p></blockquote>
<p>nginx通过上面的三个设置，当后端有响应不过来的时候，进行超时处理（记录日志），当发现超时很多了，就需要提升后端的处理能力了。</p>
<p>那么，nginx自身的处理能力是否有上限呢？当然有!</p>
<blockquote><p>worker_processes  1;<br />
worker_connections  1024;</p>
<p>max_clients = worker_processes * worker_connections </p></blockquote>
<p>当超过max_clients的用户扑上来的时候，如果幸运后端没有能力问题，那就会看到nginx在日志中要求你增加worker的提示。</p>
<p>php-fpm：</p>
<blockquote><p>pm = dynamic/static; dynamic时有最大进程最小进程之说，static时没有。只有一个上限。<br />
pm.max_children = 50;强制的一个阀门，后面的设置里，进程数不能大于这个。<br />
pm.start_servers = 20;启动时启动的fastcgi进程。<br />
pm.min_spare_servers = 5;最小fastcgi进程数量，dynamic有效<br />
pm.max_spare_servers = 35;最大fastcgi进程数量，dynamic有效</p></blockquote>
<p>php没有异步进程概念，如果要使用php作为接入层，需要自己完成NIO扩大接入能力（接触到的ICE、thrift在php中都是同步操作）。而接入能力就取决于上面的配置。</p>
<p>java:<br />
java优秀的NIO框架netty。<br />
servlet3.0实现了异步请求的context，目前还没有在平常框架中进行使用。一般的用法为comet push server，性能未知。<br />
一般来说，用java做接入层很容易变成了业务层。（但是，为什么不呢？）</p>
<blockquote><p>tomcat 7.0.x提供了servlet3.0的这一特性，CometProcessor interface。<br />
resin 4.x提供了servlet3.0的这一特性，GenericCometServlet。</p></blockquote>
<p>从名字看，大家都一致性地认为这一特性适合用来做comet server。（理论上可接入无限用户，直到费尽cpu、内存，服务器死机、jvm oom）</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/access-layer.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>nginx防hashdos模块使用帮助</title>
		<link>http://www.54chen.com/_linux_/nginx-hashdos-help.html</link>
		<comments>http://www.54chen.com/_linux_/nginx-hashdos-help.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 03:48:30 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[hashdos]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/nginx-hashdos-help.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>经过上周一周朋友们帮忙测试和bug fix，nginx_http_hashdos_module已经达到可以线上使用的水平，下面是使用记录。 下载 #wget --no-check-certificate https://github.com/54chen/nginx-http-hashdos-module/zipball/master #mv master nginx_hashdos.zip #unzip nginx_hashdos.zip 编译安装 #tar zxvf nginx-1.0.xx.tar.gz #cd nginx-1.0.xx/ #./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../54chen-nginx-http-hashdos-module-f84d909 #make &#038;&#038; make install 配置注意事项 在http段，增加如下： hashdos on; body_max_count 1000; 在各自的location段，要按照业务情况来加： client_body_buffer_size 2m; client_max_body_size 2m; &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://wiki.nginx.org/local/nginx-logo.png" alt="nginx,hashdos" /><br />
经过上周一周朋友们帮忙测试和bug fix，nginx_http_hashdos_module已经达到可以线上使用的水平，下面是使用记录。<br />
<strong>下载</strong></p>
<blockquote><p>#wget --no-check-certificate https://github.com/54chen/nginx-http-hashdos-module/zipball/master<br />
#mv master nginx_hashdos.zip<br />
#unzip nginx_hashdos.zip</p></blockquote>
<p><strong>编译安装</strong></p>
<blockquote><p>#tar zxvf nginx-1.0.xx.tar.gz<br />
#cd nginx-1.0.xx/<br />
#./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../54chen-nginx-http-hashdos-module-f84d909<br />
#make &#038;&#038; make install</p></blockquote>
<p><strong>配置注意事项</strong><br />
在http段，增加如下：</p>
<blockquote><p>
hashdos on;<br />
body_max_count 1000;
</p></blockquote>
<p>在各自的location段，要按照业务情况来加：</p>
<blockquote><p>client_body_buffer_size 2m;<br />
client_max_body_size 2m;</p></blockquote>
<p>*上述两个值一定要相等。</p>
<p>如果是普通的discuz，上传上限是1m的，可以修改为1m。<br />
如果是没有上传功能的普通网站，建议修改为512k。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/nginx-hashdos-help.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx防hashdos模块释出</title>
		<link>http://www.54chen.com/web-ral/nginx-hashdos-module.html</link>
		<comments>http://www.54chen.com/web-ral/nginx-hashdos-module.html#comments</comments>
		<pubDate>Fri, 06 Jan 2012 03:16:21 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[WEB相关]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[hashdos]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.54chen.com/web-ral/nginx-hashdos-module.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>2012.1.7 更新 编译的时候推荐使用nginx-1.0以上版本，不要加--with-debug参数编译，（感谢agentzh指出）。 hashdos这个事，严格意义上不是各种语言的错了（不过perl的确处理得很好），但是用nginx来擦屁股要干净些。 借鉴tomcat的作法，实现了下面这个nginx-http-hashdos-module，通过设置hashdos（默认on）的开关和body_max_count(默认值1000)，对nginx后面的服务进行安全防护，相比对php或者java进行patch，这或许是最好的办法了。 nginx-http-hashdos-module项目地址 https://github.com/54chen/nginx-http-hashdos-module 如何使用 1.下载zip后保存到一个目录，如~/nginx-http-hashdos-module。 2.cd nginx-1.0.9/ 3.重新编译和安装nginx ./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=/path_to/nginx-http-hashdos-module/ &#038;&#038; make &#038;&#038; make install 4.配置打开： hashdos on; body_max_count 1000; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://wiki.nginx.org/local/nginx-logo.png" alt="nginx hashdos" /><br />
<font color=blue>2012.1.7 更新<br />
编译的时候推荐使用nginx-1.0以上版本，不要加--with-debug参数编译，（感谢agentzh指出）。</font></p>
<p>hashdos这个事，严格意义上不是各种语言的错了（不过perl的确处理得很好），但是用nginx来擦屁股要干净些。<br />
借鉴tomcat的作法，实现了下面这个nginx-http-hashdos-module，通过设置hashdos（默认on）的开关和body_max_count(默认值1000)，对nginx后面的服务进行安全防护，相比对php或者java进行patch，这或许是最好的办法了。</p>
<p><strong>nginx-http-hashdos-module项目地址</strong><br />
<a href="https://github.com/54chen/nginx-http-hashdos-module">https://github.com/54chen/nginx-http-hashdos-module</a></p>
<p><strong>如何使用</strong><br />
1.下载zip后保存到一个目录，如~/nginx-http-hashdos-module。<br />
2.cd nginx-1.0.9/<br />
3.重新编译和安装nginx<br />
./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=/path_to/nginx-http-hashdos-module/ &#038;&#038; make &#038;&#038; make install<br />
4.配置打开：<br />
        hashdos on;<br />
	body_max_count 1000;<br />
	location ~ \.php$ {<br />
          fastcgi_pass 127.0.0.1:9000;<br />
          fastcgi_index index.php;<br />
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />
          include /opt/soft/nginx/conf/fastcgi_params;<br />
	  client_body_buffer_size  2m;<br />
	  client_max_body_size     2m;<br />
        }</p>
<p><strong>注意事项</strong><br />
因为计算参数都在内存中进行，所以client_body_buffer_size 与 client_max_body_size 的值一定要相等。推荐2m。</p>
<p><strong>TODO</strong><br />
改进in-file时的post分析。</p>
<p><strong>原理</strong><br />
介于微博上有网友对此文扫一眼之后以为是简单通过client_body_buffer_size和client_max_body_size来做的判断，特加此节。<br />
nginx-reqeust-body在接到请求时，根据header中的声明，判断是保存在内存还是在硬盘中，当大小超过两个buf和client_body_buffer_size大小时，会写入临时文件。<br />
防止hashdos的终极目标是filter用户的输入，所以对用户的输入参数数量进行计数。超过1000（body_max_count的默认数量）时，返回一个413给攻击者。希望不要再渔到各种高级工程师。</p>
<p><a href="https://github.com/54chen/nginx-http-hashdos-module">https://github.com/54chen/nginx-http-hashdos-module</a></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/web-ral/nginx-hashdos-module.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>riak 1.0.2安装手记</title>
		<link>http://www.54chen.com/_linux_/riak-1-0-2-install.html</link>
		<comments>http://www.54chen.com/_linux_/riak-1-0-2-install.html#comments</comments>
		<pubDate>Wed, 21 Dec 2011 12:20:02 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[riak]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/riak-1-0-2-install.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>准备三台机器： r1 r2 r3 准备erlang环境： Erlang >= R14B03 yum install gcc glibc-devel make ncurses-devel openssl-devel $ wget http://erlang.org/download/otp_src_R14B03.tar.gz $ tar zxvf otp_src_R14B03.tar.gz $ cd otp_src_R14B03 $ ./configure &#038;&#038; make &#038;&#038; sudo make install git环境(看上去是非必须的)： yum -y install git 下载地址： http://downloads.basho.com.s3-website-us-east-1.amazonaws.com/riak/CURRENT/riak-1.0.2.tar.gz &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://wiki.basho.com/images/logo_wiki.png" alt="riak" /><br />
<strong>准备三台机器：</strong><br />
r1<br />
r2<br />
r3</p>
<p><strong>准备erlang环境：</strong><br />
Erlang >= R14B03<br />
yum install gcc glibc-devel make ncurses-devel openssl-devel<br />
$ wget http://erlang.org/download/otp_src_R14B03.tar.gz<br />
$ tar zxvf otp_src_R14B03.tar.gz<br />
$ cd otp_src_R14B03<br />
$ ./configure &#038;&#038; make &#038;&#038; sudo make install</p>
<p><strong>git环境(看上去是非必须的)：</strong><br />
yum -y install git</p>
<p><strong>下载地址：</strong></p>
<p>http://downloads.basho.com.s3-website-us-east-1.amazonaws.com/riak/CURRENT/riak-1.0.2.tar.gz</p>
<blockquote><p>
cd riak-1.0.2<br />
make rel</p></blockquote>
<p><strong>修改配置文件后启动</strong><br />
riak start<br />
riak-admin join<br />
过程完全同0.142<br />
<a href="http://www.54chen.com/_linux_/riak-source-install-run.html">http://www.54chen.com/_linux_/riak-source-install-run.html</a><br />
<strong>与0.1.42相比：</strong><br />
erlang环境要求R14B03及以上。低版本会出现this emulator supports only up to 149的make错误。</p>
<p><strong>使用leveldb为存储引擎：</strong><br />
默认引擎还是bitcask，需要修改配置文件app.config<br />
{storage_backend, riak_kv_bitcask_backend}<br />
改为：<br />
{storage_backend, riak_kv_eleveldb_backend}</p>
<p><strong>官方说明：</strong><br />
bitcask适用于key有限，而需要最大量的吞吐量和数据持久化情况。<br />
leveldb适用于大量的key。<br />
<strong><br />
官方java client压力测试结果：</strong><br />
1cpu 8G的机器3个 笔记本运行压力程序 读写比3:1 6并发 1k大小的value<br />
PB：2500ops  99.9%的操作在22ms内。<br />
HTTP: 1000ops  99.9%的操作在30ms内。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/riak-1-0-2-install.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>velocity2011讲师经验总结及velocity2011的ppt下载</title>
		<link>http://www.54chen.com/web-ral/velocity-china-2011-ppt-dow.html</link>
		<comments>http://www.54chen.com/web-ral/velocity-china-2011-ppt-dow.html#comments</comments>
		<pubDate>Wed, 07 Dec 2011 01:03:31 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[WEB相关]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[资料文档]]></category>
		<category><![CDATA[velocity]]></category>

		<guid isPermaLink="false">http://www.54chen.com/web-ral/velocity-china-2011-ppt-dow.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>总结： 1）会场有点小，比较热 2）讲的东西为了照顾更多人，比较片面，如果有想听深入的同学，可以参加我们哥学社的吃喝会。 3）会上遇到了douban强宁大侠、安全宝的冯大侠、还有一位来自清华的主任、以及各位一线的朋友恕不能一一列出，深感荣幸。 互联网创业服务器运维工具集 View more presentations from zhen chen.<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img03.taobaocdn.com/imgextra/i3/T13gR3Xa4cXXcFX9c3_050845.jpg" alt="velocity" /></p>
<p>总结：<br />
1）会场有点小，比较热<br />
2）讲的东西为了照顾更多人，比较片面，如果有想听深入的同学，可以参加我们<a href="http://blog-brother.com" target=_blank>哥学社</a>的吃喝会。<br />
3）会上遇到了douban强宁大侠、安全宝的冯大侠、还有一位来自清华的主任、以及各位一线的朋友恕不能一一列出，深感荣幸。</p>
<div style="width:425px" id="__ss_10490088"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/54chen/ss-10490088" title="互联网创业服务器运维工具集">互联网创业服务器运维工具集</a></strong><object id="__sse10490088" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=random-111206183925-phpapp01&#038;stripped_title=ss-10490088&#038;userName=54chen" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/><embed name="__sse10490088" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=random-111206183925-phpapp01&#038;stripped_title=ss-10490088&#038;userName=54chen" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/54chen">zhen chen</a>.</div>
</div>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/web-ral/velocity-china-2011-ppt-dow.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>移动互联网api设计实践</title>
		<link>http://www.54chen.com/_linux_/mobile-net-api-design.html</link>
		<comments>http://www.54chen.com/_linux_/mobile-net-api-design.html#comments</comments>
		<pubDate>Mon, 05 Dec 2011 09:42:02 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/mobile-net-api-design.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>过去一年时间里，都在做中国移动互联网下的API设计工作，所面对的情况可能是最具中国特色的了。如果你在尝试构架一整套的新的API供你的客户端使用，可以尝试以下的几点： 1）api所使用协议，要能够不怕被加js、加广告和各种代码。 全国各地的运营商，有习惯挂广告、加代码等等，要做的事情就是在客户端做各种解析判断。实践证明，这帮孙子的设备是检测http协议的head头里的content-type，如果是html/text则会加，如果是text/json就不加了，所以，你懂的。 2）api可视化 你的app上架了，后端也布好了。然后呢，就天天看下载量。但后端好坏一问三不知。所以在设计api时，要提前回答以下问题： 1.此时此刻，有多少个app正在调用这些api，每分钟多少个？ 2.他们（api）有快？ 3.能否很简单地通过浏览器快速debug？ 4.能否快速禁止单个用户？ 3）链路 在幅员辽阔的我国，总是一个地方到一个地方的IDC直接就ping不通（移动互联网下更甚）。于是需要花钱自己打通这些地方，没有专线，只有代理再代理。 4）api quota与perfcounter 对api进行quota限制，针对每个api每个人，都有限额。 这个限制的传统做法： 1.每天的上限调用次数。每天半夜清空，一天一个量累计。 2.每分钟的频度。这个防止有恶性的突发情况。 上述二者，缺一不可。 perfcounter用于对api的监控设计指标，如果一个api有异常，应当十分灵敏地得出结论，而不是误报连连。<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img02.taobaocdn.com/imgextra/i2/13078490/T28EicXgtXXXXXXXXX_!!13078490.jpg" alt="api quota perf design" /><br />
过去一年时间里，都在做中国移动互联网下的API设计工作，所面对的情况可能是最具中国特色的了。如果你在尝试构架一整套的新的API供你的客户端使用，可以尝试以下的几点：<br />
<strong>1）api所使用协议，要能够不怕被加js、加广告和各种代码。</strong><br />
全国各地的运营商，有习惯挂广告、加代码等等，要做的事情就是在客户端做各种解析判断。实践证明，这帮孙子的设备是检测http协议的head头里的content-type，如果是html/text则会加，如果是text/json就不加了，所以，你懂的。</p>
<p><strong>2）api可视化</strong><br />
你的app上架了，后端也布好了。然后呢，就天天看下载量。但后端好坏一问三不知。所以在设计api时，要提前回答以下问题：<br />
1.此时此刻，有多少个app正在调用这些api，每分钟多少个？<br />
2.他们（api）有快？<br />
3.能否很简单地通过浏览器快速debug？<br />
4.能否快速禁止单个用户？</p>
<p><strong>3）链路</strong><br />
在幅员辽阔的我国，总是一个地方到一个地方的IDC直接就ping不通（移动互联网下更甚）。于是需要花钱自己打通这些地方，没有专线，只有代理再代理。</p>
<p><strong>4）api quota与perfcounter</strong><br />
对api进行quota限制，针对每个api每个人，都有限额。<br />
这个限制的传统做法：<br />
1.每天的上限调用次数。每天半夜清空，一天一个量累计。<br />
2.每分钟的频度。这个防止有恶性的突发情况。<br />
上述二者，缺一不可。<br />
perfcounter用于对api的监控设计指标，如果一个api有异常，应当十分灵敏地得出结论，而不是误报连连。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/mobile-net-api-design.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>riak源码阅读手记 操作列表及supervisorTree一览</title>
		<link>http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html</link>
		<comments>http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html#comments</comments>
		<pubDate>Tue, 18 Oct 2011 08:07:22 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[riak]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>基于0.14.2的记录，1.0的变化会在后续记录。 riak源码阅读手记一 初出茅庐 项目入口 http://www.54chen.com/_linux_/riak-source.html riak源码阅读手记二 左右开弓 启动 http://www.54chen.com/_linux_/riak-cource-code.html riak源码阅读手记 运行安装 http://www.54chen.com/_linux_/riak-source-install-run.html 一些常用的指令： http://wiki.basho.com/Command-Line-Tools.html#riak-admin riak源码阅读手记 压力测试 http://www.54chen.com/_linux_/riak-benchmark.html riak源码阅读手记 操作列表及supervisorTree一览 http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html [山寨收集操作列表] 看系统状况，有各种内存cpu硬盘的情况 bin/riak-admin status 节点更换新的ip地址： 如果是所有的节点都换，那在停下来集群，在每个节点都依次运行: ./riak-admin reip riak@192.168.103.9 riak@10.235.2.226 ./riak-admin reip riak@192.168.97.48 riak@10.235.2.183 ./riak-admin reip riak@192.168.100.52 riak@10.235.2.138 依次去对应的节点，修改etc: sed&#160;-i&#160;'s/192.168.103.9/10.235.2.226/g'&#160;app.config&#160;&#160; &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>基于0.14.2的记录，1.0的变化会在后续记录。<br />
<img src="http://wiki.basho.com/images/logo_wiki.png" alt="riak" /><br />
riak源码阅读手记一 初出茅庐 项目入口<br />
<a href="http://www.54chen.com/_linux_/riak-source.html">http://www.54chen.com/_linux_/riak-source.html</a><br />
riak源码阅读手记二 左右开弓 启动<br />
<a href="http://www.54chen.com/_linux_/riak-cource-code.html">http://www.54chen.com/_linux_/riak-cource-code.html</a><br />
riak源码阅读手记 运行安装<br />
<a href="http://www.54chen.com/_linux_/riak-source-install-run.html">http://www.54chen.com/_linux_/riak-source-install-run.html</a><br />
一些常用的指令：<br />
<a href="http://wiki.basho.com/Command-Line-Tools.html#riak-admin">http://wiki.basho.com/Command-Line-Tools.html#riak-admin</a><br />
riak源码阅读手记 压力测试<br />
<a href="http://www.54chen.com/_linux_/riak-benchmark.html">http://www.54chen.com/_linux_/riak-benchmark.html</a><br />
riak源码阅读手记 操作列表及supervisorTree一览<br />
<a href="http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html">http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html</a><br />
<strong>[山寨收集操作列表]</strong></p>
<p>看系统状况，有各种内存cpu硬盘的情况<br />
bin/riak-admin status</p>
<p>节点更换新的ip地址：<br />
如果是所有的节点都换，那在停下来集群，在每个节点都依次运行:<br />
./riak-admin reip riak@192.168.103.9 riak@10.235.2.226<br />
./riak-admin reip riak@192.168.97.48 riak@10.235.2.183<br />
./riak-admin reip riak@192.168.100.52 riak@10.235.2.138</p>
<p>依次去对应的节点，修改etc:</p>
<div class="chen-hl">
<div class="bar"></div>
<ol class="dp-perl" start="1">
<li class="alt"><span><span>sed&nbsp;-i&nbsp;'</span><span class="keyword">s</span><span>/192.168.103.9/10.235.2.226/g'&nbsp;app.config&nbsp;&nbsp;</span></span></li>
<li class=""><span>sed&nbsp;-i&nbsp;'<span class="keyword">s</span><span>/192.168.103.9/10.235.2.226/g'&nbsp;vm.args&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>&nbsp;&nbsp;</span></li>
<li class=""><span>sed&nbsp;-i&nbsp;'<span class="keyword">s</span><span>/192.168.97.48/10.235.2.183/g'&nbsp;app.config&nbsp;&nbsp;</span></span></li>
<li class="alt"><span>sed&nbsp;-i&nbsp;'<span class="keyword">s</span><span>/192.168.97.48/10.235.2.183/g'&nbsp;vm.args&nbsp;&nbsp;</span></span></li>
<li class=""><span>&nbsp;&nbsp;</span></li>
<li class="alt"><span>sed&nbsp;-i&nbsp;'<span class="keyword">s</span><span>/192.168.100.52/10.235.2.138/g'&nbsp;app.config&nbsp;&nbsp;</span></span></li>
<li class=""><span>sed&nbsp;-i&nbsp;'<span class="keyword">s</span><span>/192.168.100.52/10.235.2.138/g'&nbsp;vm.args&nbsp;&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<p>进入运行着的集群：<br />
./riak attach<br />
ctrl+d退出</p>
<p>看ring的分布情况：<br />
>{ok,Ring} = riak_core_ring_manager:get_my_ring().</p>
<p><strong>[看一点代码]</strong><br />
riak_kv_app -> riak_core->riak_core_sup[supervisor]-><br />
riak_core_sup<br />
|-riak_core_handoff_manager  handoff管理  gen_server<br />
|-riak_core_handoff_listener    handoff接收  gen_nb_server<br />
|-riak_core_ring_events           处理ring变化  gen_event<br />
|-riak_core_ring_manager       ring管理   gen_server2<br />
|-riak_core_node_watcher_events   节点侦察 gen_event<br />
|-riak_core_node_watcher                节点 gen_server<br />
|-riak_core_gossip                   gossip协议 gen_server</p>
<p><strong>[riak里的自定义behaviour]</strong><br />
-gen_nb_server from gen_server<br />
-gen_server2   gen_server的一个拷贝 增加了pxxx的办法及增加了许多参数<br />
-riak_core_vnode from gen_fsm<br />
riak_kv:<br />
-riak_kv_backend  Riak backend behaviour </p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/riak-source-notes-operation-supvisor-detail.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>thrift最佳实践:版本与兼容</title>
		<link>http://www.54chen.com/_linux_/thrift-versioning-compatibility.html</link>
		<comments>http://www.54chen.com/_linux_/thrift-versioning-compatibility.html#comments</comments>
		<pubDate>Wed, 28 Sep 2011 07:40:58 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[thrift]]></category>
		<category><![CDATA[versioning]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/thrift-versioning-compatibility.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>十分苦逼的api提供过程。一次提供，终身负责制。 "API design is like sex: Make one mistake and support it for the rest of your life." - @joshbloch Structs： 在许多系统里面，被称做message. 协议随着岁月而演变，如果一个已经存在的消息类型不再满足需求，但是你仍然想使用原来使用thrift文件生成的代码，比如你想在现在的消息类型上增加一个额外的字段。 不用担心人，不搞坏原来的任何代码而更新消息类型，是非常简单的，只需要时刻记录以下的规则： 1.不要修改现存的任何已经存在字段的数字标签 2.任何新增的字段应该是optional的，这就意味着，所有新定义产生的代码都能解析新老的格式，因为一定会有任何一个标上required的元素。你应该设置可能的默认值给这个元素，让新代码与老数据也能正常协作。与此类似，新数据也能被老代码解析，老的实现解析时会忽略新的字段。尽管如此，未知的字段不能被丢弃，并且如果消息被延迟序列化，未知的字段也会被一起序列化，因此当消息到达新代码的时候，新字段依旧可用。 3.当你更新的消息类型里不再包括相关的标签数字时，非required字段可以删除。（把这个废字段改名，比如说加个前缀OBSOLETE_ ，可以防止未来维护.thrift文件人误用原来的数字，这做法可能更好。) 4.修改默认值基本上是OK的，但是你记得这个默认值永远不会“串线”。比如，如果程序收到一个在某个字段没有值的消息，程序会看那个版本里定义的默认值。这可能会导致得不到正确的默认值。 cassandra的thrift定义：http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.thrift?view=co fb303的定义：http://svn.apache.org/repos/asf/thrift/trunk/contrib/fb303/if/fb303.thrift scribe的定义：https://github.com/facebook/scribe/blob/master/if/scribe.thrift from:ThriftThe Missing Guide<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img04.taobaocdn.com/imgextra/i4/T1gzmqXXdpXXcwYVo0_034121.jpg" alt="facebook,thrift" /></p>
<p>十分苦逼的api提供过程。一次提供，终身负责制。</p>
<blockquote><p>"API design is like sex: Make one mistake and support it for the rest of your life." - @joshbloch
</p></blockquote>
<p><strong>Structs：</strong><br />
在许多系统里面，被称做message.</p>
<p>协议随着岁月而演变，如果一个已经存在的消息类型不再满足需求，但是你仍然想使用原来使用thrift文件生成的代码，比如你想在现在的消息类型上增加一个额外的字段。                          </p>
<p>不用担心人，不搞坏原来的任何代码而更新消息类型，是非常简单的，只需要时刻记录以下的<strong>规则</strong>：</p>
<blockquote><p>
1.不要修改现存的任何已经存在字段的数字标签</p></blockquote>
<blockquote><p>2.任何新增的字段应该是optional的，这就意味着，所有新定义产生的代码都能解析新老的格式，因为一定会有任何一个标上required的元素。你应该设置可能的默认值给这个元素，让新代码与老数据也能正常协作。与此类似，新数据也能被老代码解析，老的实现解析时会忽略新的字段。尽管如此，未知的字段不能被丢弃，并且如果消息被延迟序列化，未知的字段也会被一起序列化，因此当消息到达新代码的时候，新字段依旧可用。</p></blockquote>
<blockquote><p>3.当你更新的消息类型里不再包括相关的标签数字时，非required字段可以删除。（把这个废字段改名，比如说加个前缀OBSOLETE_ ，可以防止未来维护.thrift文件人误用原来的数字，这做法可能更好。)</p></blockquote>
<blockquote><p>4.修改默认值基本上是OK的，但是你记得这个默认值永远不会“串线”。比如，如果程序收到一个在某个字段没有值的消息，程序会看那个版本里定义的默认值。这可能会导致得不到正确的默认值。
</p></blockquote>
<p>cassandra的thrift定义：http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.thrift?view=co<br />
fb303的定义：http://svn.apache.org/repos/asf/thrift/trunk/contrib/fb303/if/fb303.thrift<br />
scribe的定义：https://github.com/facebook/scribe/blob/master/if/scribe.thrift</p>
<p><em>from:ThriftThe Missing Guide</em></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/thrift-versioning-compatibility.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用supervisord管理杂乱的服务</title>
		<link>http://www.54chen.com/java-ee/supervisord-manage-service.html</link>
		<comments>http://www.54chen.com/java-ee/supervisord-manage-service.html#comments</comments>
		<pubDate>Wed, 21 Sep 2011 06:57:24 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[supervisord]]></category>

		<guid isPermaLink="false">http://www.54chen.com/java-ee/supervisord-manage-service.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>Supervisord是用Python实现的一款非常实用的进程管理工具，在批量服务化管理时特别有效。 环境 centos python2.4 安装 wget http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0a10.tar.gz#md5=99c6fbd45bade87301296b7a597fb68e tar zxvf supervisor-3.0a10.tar.gz cd supervisor-3.0a10 python setup.py install 如果上述遇到问题，请按如下操作。 依赖setuptools安装 wget http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c11-py2.4.egg#md5=bd639f9b0eac4c42497034dec2ec0c2b sh setuptools-0.6c11-py2.4.egg 产生基础配置文件 echo_supervisord_conf > /etc/supervisord.conf 配置 [inet_http_server]前面的分号去掉; 定义port=192.168.1.1:8888 启动 supervisord -c /etc/supervisord.conf 查看 浏览器打开 http://192.168.1.1:8888 深入配置 [program:service] command=sh /opt/soft/service/run.sh ; &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://supervisord.org/_static/logo_hi.gif" alt="supervisord" /></p>
<p>Supervisord是用Python实现的一款非常实用的进程管理工具，在批量服务化管理时特别有效。</p>
<p><strong>环境</strong></p>
<p>centos<br />
python2.4</p>
<p><strong>安装 </strong></p>
<p>wget http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0a10.tar.gz#md5=99c6fbd45bade87301296b7a597fb68e</p>
<p>tar zxvf supervisor-3.0a10.tar.gz<br />
cd supervisor-3.0a10<br />
python setup.py install<br />
如果上述遇到问题，请按如下操作。</p>
<p><strong>依赖setuptools安装</strong></p>
<p>wget http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c11-py2.4.egg#md5=bd639f9b0eac4c42497034dec2ec0c2b<br />
sh setuptools-0.6c11-py2.4.egg</p>
<p><strong>产生基础配置文件</strong></p>
<p>echo_supervisord_conf > /etc/supervisord.conf</p>
<p><strong>配置</strong></p>
<p>[inet_http_server]前面的分号去掉;<br />
定义port=192.168.1.1:8888</p>
<p><strong>启动</strong></p>
<p>supervisord -c /etc/supervisord.conf</p>
<p><strong>查看</strong></p>
<p>浏览器打开 http://192.168.1.1:8888<br />
<strong><br />
深入配置</strong></p>
<blockquote><p>[program:service]<br />
command=sh /opt/soft/service/run.sh  ; the program (relative uses PATH, can take args)<br />
process_name=%(program_name)s ; process_name expr (default %(program_name)s)<br />
numprocs=1                    ; number of processes copies to start (def 1)<br />
directory=/opt/soft/service/                ; directory to cwd to before exec (def no cwd)<br />
autostart=true                ; start at supervisord start (default: true)<br />
autorestart=true              ; retstart at unexpected quit (default: true)<br />
stopsignal=QUIT               ; signal used to kill process (default TERM)<br />
stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)</p></blockquote>
<p>以上配置了一个shell脚本的启动和stop过程。<br />
一般java程序都喜欢在一个shell脚本内初始化classpath，再执行java main。<br />
直接在shell中run java会出现stop失败的情况，在启动前添加 exec即可。</p>
<blockquote><p>#!/bin/sh<br />
export CLASSPATH=.<br />
for jarpath in `ls library/*.jar`<br />
do<br />
    CLASSPATH=$CLASSPATH:$jarpath<br />
done<br />
export CLASSPATH=$CLASSPATH<br />
exec java com.chen.main;
</p></blockquote>
<p><strong><br />
帮助</strong></p>
<blockquote><p>supervisord，初始启动Supervisord，启动、管理配置中设置的进程。<br />
supervisorctl stop programxxx，停止某一个进程(programxxx)，programxxx为[program:chatdemon]里配置的值，这个示例就是chatdemon。<br />
supervisorctl start programxxx，启动某个进程<br />
supervisorctl restart programxxx，重启某个进程<br />
supervisorctl stop all，停止全部进程，注：start、restart、stop都不会载入最新的配置文件。<br />
supervisorctl reload，载入最新的配置文件，并按新的配置启动、管理所有进程。<br />
supervisorctl  reread，当一个服务由自动启动修改为手动启动时执行一下就ok</p></blockquote>
<p><strong>如何添加进程不启动所有的服务进程</strong></p>
<blockquote><p>1）修改/etc/supervisord.conf<br />
2）supervisorctl  reread<br />
3）supervisorctl  add xxservice
</p></blockquote>
<p><strong>如何删除进程不启动所有的服务进程</strong></p>
<blockquote><p>1）修改/etc/supervisord.conf<br />
2）supervisorctl  reread<br />
3）supervisorctl  update
</p></blockquote>
<p>http://smarden.org/runit/runscripts.html 一些可参考的启动配置</p>
<p><strong>supervisord开机自启动</strong><br />
chkconfig --add supervisord #加为服务<br />
运行ntsysv，选中supervisord启动系统时跟着启动。<br />
[/etc/rc.d/init.d/supervisord]</p>
<blockquote><p>#!/bin/sh<br />
#<br />
# /etc/rc.d/init.d/supervisord<br />
#<br />
# Supervisor is a client/server system that<br />
# allows its users to monitor and control a<br />
# number of processes on UNIX-like operating<br />
# systems.<br />
#<br />
# chkconfig: - 64 36<br />
# description: Supervisor Server<br />
# processname: supervisord</p>
<p># Source init functions<br />
. /etc/rc.d/init.d/functions</p>
<p>prog="supervisord"</p>
<p>prefix="/usr/"<br />
exec_prefix="${prefix}"<br />
prog_bin="${exec_prefix}/bin/supervisord"<br />
PIDFILE="/var/run/$prog.pid"</p>
<p>start()<br />
{<br />
        echo -n $"Starting $prog: "<br />
        daemon $prog_bin --pidfile $PIDFILE<br />
        [ -f $PIDFILE ] &#038;&#038; success $"$prog startup" || failure $"$prog startup"<br />
        echo<br />
}</p>
<p>stop()<br />
{<br />
        echo -n $"Shutting down $prog: "<br />
        [ -f $PIDFILE ] &#038;&#038; killproc $prog || success $"$prog shutdown"<br />
        echo<br />
}</p>
<p>case "$1" in</p>
<p>  start)<br />
    start<br />
  ;;</p>
<p>  stop)<br />
    stop<br />
  ;;</p>
<p>  status)<br />
        status $prog<br />
  ;;</p>
<p>  restart)<br />
    stop<br />
    start<br />
  ;;</p>
<p>  *)<br />
    echo "Usage: $0 {start|stop|restart|status}"<br />
  ;;</p>
<p>esac
</p></blockquote>
<p><strong>注意 </strong><br />
不带参数运行supervisord是以daemon方式运行。<br />
把supervisord加入到开机启动项里就可以完成监控进程的功能了。<br />
当supervisord以非daemon方式运行时，杀掉supervisord后，被监控的进程也退出了。<br />
而以daemon方式运行，杀掉supervisord对被监控进程无影响。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/java-ee/supervisord-manage-service.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

