<?xml version="1.0" encoding="UTF-8" ?>
  <rss version="2.0">
    <channel>

<title>Perpetuum Vestigium</title>
      <link>http://entelechie.ycool.com/</link>
      <description><![CDATA[]]></description>
      <pubDate>Wed, 23 Jul 2008 14:07:55 GMT</pubDate>
      <lastBuildDate>Wed, 23 Jul 2008 14:07:55 GMT</lastBuildDate>
      <image>
        <url>http://sta.yculblog.com/images/logo/general-88x31.gif</url>
        <title>Perpetuum Vestigium</title>
        <link>http://entelechie.ycool.com/</link>
      </image>
<item>
        <title>游泳</title>
        <link>http://entelechie.ycool.com/post.2931654.html</link>
        <description><![CDATA[昨天去了一趟公司的健身房，器械很不错，更衣室没有一点异味，还有洒满阳光的泳池。<br />
身体状态也不错，这么久没下水了还能游个400米，比较的心满意足了。<br />
<br />
早起、用心干活、下班游泳、隔日健身，这样的生活状态很好。<br />
终于有了一点传说中的归属感和节奏感。<br />
<br />
还是忙，争取周整理些西藏的照片放上来：）...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2931654.html</guid>
        <pubDate>Tue, 22 Jul 2008 23:07:02 GMT</pubDate>

      </item>

      <item>
        <title>在北京了</title>
        <link>http://entelechie.ycool.com/post.2929443.html</link>
        <description><![CDATA[从杭州培来了，感觉培训比上班还累。<br />
在北京待了一年，都有些不习惯南方粘呼呼的炎热了。<br />
<br />
期间见到了老包、周总和netsnail师兄：<br />
老包现在在淘宝的百花丛中是难逃招蜂引蝶的命运；<br />
周总的徕卡毒性很大，男人都难逃对精密器械的那点小小的热爱，either do I；<br />
netsnail还是嫩么滴屌、嫩么滴怪蜀黍。。。<br />
<br />
这一趟，基本上断了去杭州的念头，一个公司还是贵在他完善的制度。<br />
至于这次的其他收获，比如团队合作，待我自己理清楚先。<br />...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2929443.html</guid>
        <pubDate>Sat, 19 Jul 2008 12:07:27 GMT</pubDate>

      </item>

      <item>
        <title>最后的工作日</title>
        <link>http://entelechie.ycool.com/post.2902998.html</link>
        <description><![CDATA[刚写完了三篇文档，everything is done。<br />
想找人帮我在公司的logo前拍张照片留念，发现保安都下班了。<br />
<br />
回家睡觉。。。Mama, I'm coming home.<br />
<br />
<br />
<embed width="200" height="30" src="http://jansplacetoputstuff.com/myspace%20stuff/Ozzy%20Osbourne%20-%20Mama,%20I'm%20Coming%20Home.mp3" type="audio/mpeg" play="true" autostart="true" loop="true"></embed><br />...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2902998.html</guid>
        <pubDate>Fri, 06 Jun 2008 18:06:46 GMT</pubDate>

      </item>

      <item>
        <title>damn myself</title>
        <link>http://entelechie.ycool.com/post.2902910.html</link>
        <description><![CDATA[最近想的，无非是车子、房子和女子。<br />
<br />
so why I am fuckin here.. I lost myself.<br />
Peking, I am here to kick your ass....
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2902910.html</guid>
        <pubDate>Fri, 06 Jun 2008 15:06:18 GMT</pubDate>

      </item>

      <item>
        <title>南迦巴瓦偶来鸟</title>
        <link>http://entelechie.ycool.com/post.2901261.html</link>
        <description><![CDATA[亲耐滴帝国，给偶一张passcard吧。。<br />
如果8发边防证，偶还口以切哪里咩&hellip;&hellip;<br />
<br />
土人说：我有粽子；我说：我有肚子。<br />
眼下的问题是赶回家过端午节。。。<br />
<br />
<br />
<br />
ps:在某公司完成滴最后一个需求：<br />
您滴服务器太快鸟，请每次发包后sleep()一下。。<br />
我 囧rz～～...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2901261.html</guid>
        <pubDate>Tue, 03 Jun 2008 15:06:52 GMT</pubDate>

      </item>

      <item>
        <title>erlang optimization[待续]</title>
        <link>http://entelechie.ycool.com/post.2897868.html</link>
        <description><![CDATA[<strong>1. request per second</strong><br />
a jerky server model<br />
这次做的是一个http log服务器，需要在有限的资源下支持尽可能高的PV。<br />
提高PV，无非是改进两个指标：1. Connect Time；2. Process Time。<br />
其实这两个问题都是一个思路，后面我们可以看到。<br />
<br />
对于传统的长连接TCP服务，鉴于Erlang的低成本线程调度，一般采取的方案是每个TCP连接在gen_tcp:accept时spawn一个独立的线程处理后续的C/S交互。<br />
但是对于眼下的http log服务，首先并不是一个keep-alive的连接：我们的设计目标是尽可能快的返回http响应并关闭TCP Socket，传统模型不是非常适用。<br />
于是便有了一种callback模型：用一个daemon线程专司接收消息并创建监听线程，由监听线程阻塞在gen_tcp:accept上，例子如下：<br />
start_server() -&gt;<br />
&nbsp;&nbsp;&nbsp; DT = spawn(test, daemon, [Listen_Sock]),<br />
&nbsp;&nbsp;&nbsp; DT ! {new}.<br />
<br />
daemon(Listen_Sock) -&gt;<br />
&nbsp;&nbsp;&nbsp; receive<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  {new} -&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;  spawn(test, proc, [Listen_Sock, self()])<br />
&nbsp;&nbsp;&nbsp; end.<br />
<br />
proc(Listen_Sock, DT) -&gt;<br />
&nbsp;&nbsp;&nbsp; Client = gen_tcp:accept(Listen_Sock),<br />
&nbsp;&nbsp;&nbsp; DT ! {new},<br />
&nbsp;&nbsp;&nbsp; gen_tcp:send(Client, &quot;HTTP 200\n\r&quot;),<br />
&nbsp;&nbsp;&nbsp; % do further process <br />
这种方案的好处在于，把spawn的开销从http处理中剥离了开来：<br />
所有的处理线程都是预生成后阻塞在哪里，gen_tcp:accept后无需spawn直接执行后续的代码。<br />
再配合+K true参数使用kqueue模型，可以预先生成多个proc的线程阻塞在accept上，可极大提高性能。<br />
<br />
至于Process Time，同样是依赖预处理的思路：<br />
因为http log服务涉及到Set-Cookie等操作，取localtime并格式化的过程中涉及到大量系统调用和字符串操作，在Erlang中开销不小。<br />
解决办法是在daemon中预先生成好不同情况下需要返回的各色字符串，作为参数传给spawn出来的proc线程，剩下的操作无非是 条件判断-&gt;发送。<br />
<br />
还有非常重要的一点是根据县城内处理数据的规模，使用spawn_opt设置合适的process heap大小<br />
因为避免后期的heap扩充是开销非常大的一种操作，在轻量级线程内尤其要避免。<br />
<br />
<strong><br />
2. normal optimization[待续]</strong><br />
为了保证daemon进程的栈空间不增长，必须把函数写成tail-recursive。<br />
这个积累还是很惊人的，而且属于不可回收空间；<br />
如果你的服务运行那个多日因为内存问题挂掉，可以检查下所有的守护线程。<br />
<br />
<strong> 3. memory (crash dump)[待续]</strong><br />
<br />
<strong>4. 垃圾回收</strong><br />
期间遇到了比较到的严重的内存问题，造成服务器几个小时候因为alloc()失败而崩溃；<br />
查看erlang:memory()的信息，发现processes占用绝大部分内存，开始误认为是产生了大量无用线程；<br />
最后确诊还是因为deque大量申请释放，造成heap的回收效率问题以至于内存不够用。<br />
使用spawn_opt设置fullsweep_after为0没有用，非常奇怪；必须显式调用erlang:garbage_collect()。<br />
<br />
经过这几天压力测试，Erlang的garbage collection机制还是相当强健的：<br />
在每秒近万次的不规则数据申请、释放的压力下，十几个小时后运行依然稳健，整体回收效率很高并且没有拖累到业务逻辑的性能。<br />
可怜的Java&hellip;&hellip;&hellip;&hellip;<br />
<br />
<strong> 5. profiling[待续]</strong><br />
cprof<br />
<br />
先列个题头，回头再写。。。<br />
<br />
迅猛把活干完，然后去旅行。<br />
What a wonderful world.<br />
<br />
<br />
Ver. 3.14<br />
周末肉过来了，去八达岭过了儿童节，很累。<br />
所以洗洗睡了先，改日再写。<br />
<br />
Ver. 3.141<br />
在家了，一个劲的下雨。我华丽的假期...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2897868.html</guid>
        <pubDate>Mon, 02 Jun 2008 14:06:47 GMT</pubDate>
<category>优化</category>

        <category>profile</category>

        <category>dump</category>

        <category>optimization</category>

        <category>erlang</category>

        <category>accept</category>

        <category>并发</category>

        <category>gen_tcp</category>
      </item>

      <item>
        <title>Yesterday is a landmark</title>
        <link>http://entelechie.ycool.com/post.2894182.html</link>
        <description><![CDATA[Everything is settled down.And I am entirely refreshed.<br />
<br />
The most urgent is a vocation....
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2894182.html</guid>
        <pubDate>Thu, 22 May 2008 00:05:58 GMT</pubDate>

      </item>

      <item>
        <title>God bless Post-Tsing Empire</title>
        <link>http://entelechie.ycool.com/post.2889224.html</link>
        <description><![CDATA[兄弟们都安好，只是担心汶川的人民。<br />
那一年的十月，在古尔沟看到救援队露营留下的余灰，我确信他们都是好人。<br />
<br />
有人说这是上帝对人类的惩罚，但是为什么让那些淳朴的人民来遭难；<br />
而我们这些生活在肮脏的城市里的人却安然无恙，甚至继续玩世不恭，<br />
像对待超级女声一样带着笑意说出阵亡的数字，继续娱乐一切。<br />
<br />
<br />
Anyway, God bless our fellow.<br />
<br />
<br />
BTW: <br />
部队虽然抵达了<font color="#800000">汶川县</font>，但是映秀离<font color="#800000">汶川县城</font>还很远，现在的道路损毁情况，只能看十五军了，上帝保佑。...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2889224.html</guid>
        <pubDate>Wed, 14 May 2008 01:05:13 GMT</pubDate>

      </item>

      <item>
        <title>C Programming FAQ读书笔记</title>
        <link>http://entelechie.ycool.com/post.2888443.html</link>
        <description><![CDATA[花了两天时间把C FAQ又过了一遍，发现了从前忽略的一些点。<br />
<br />
1. 虽然K&amp;R上说结构体必须memcpy或者一个元素一个元素的赋值，其实struct可以直接用=操作符做整体拷贝的；<br />
2. offsetof()，用来计算结构体内成员偏移的宏；<br />
3. 如果函数的返回值为struct，C也会类似C++的在函数形参里加上一个struct *指针的；<br />
4. 可能大家都习惯malloc后做强转了，其实这是含糊的C/CPP编译器混用的恶果。作为C程序，其一void *可以自动转换，其二因为C默认函数返回int，如果malloc没有正确申明，int也会被错误的强转为指针且不报错；<br />
5. sequence point间evaluation的顺序是不保证的；<br />
6. void **是一个很无厘头的东西，void *作为万用指针，void **是什么？指向万用指针的特型指针？<br />
7. 关于申明指针char *p还是char* p的问题，char* p, c这样误导性的代码就是答案。永远写成前者，这不是风格问题；<br />
8. 3[&quot;abcde&quot;] 等于 3 + &quot;abcde&quot; 等于&quot;abcde&quot; +3 等于&quot;abcde&quot;[3]，华丽的C语言。...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2888443.html</guid>
        <pubDate>Mon, 12 May 2008 16:05:24 GMT</pubDate>
<category>faq</category>

        <category>programming</category>

        <category>c</category>
      </item>

      <item>
        <title>写给成都的DX们</title>
        <link>http://entelechie.ycool.com/post.2887244.html</link>
        <description><![CDATA[&quot;Fight and you may die, run and you'll live. At least a while. And dying in your beds many years from now, would you be willing to trade all the days from this day to that for one chance, just one chance to come back here and tell our enemies that they may take our lives, but they'll never take our freedom.&quot;<br />
<br />
&nbsp;- William Wallace<br />
<br />
<br />
Background:<br />
《<a href="http://news.sina.com.cn/c/l/2008-05-11/120315516345.shtml">成都警方处罚利用四川石化项目散布谣言者</a>》；<br />
上周的南方周末有半版的PX报道，我也觉得四川政府在满足民众知情权之前，如此强势的打压不是非常合理。<br />
<br />
PS：<br />
还好不是喉舌大报的新闻，不然英勇的南瓜泡沫死定了。...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2887244.html</guid>
        <pubDate>Sun, 11 May 2008 05:05:24 GMT</pubDate>

      </item>

      <item>
        <title>Erlang</title>
        <link>http://entelechie.ycool.com/post.2885048.html</link>
        <description><![CDATA[1. 网络报文头需要先list_to_bitstring转成bitstring，然后用过bit syntax进行解析；<br />
2. 对于数据结构，处理起来是list好，访问起来是array好，使用array:to_list(), array:from_list()进行转换；<br />
3. 明天要研究下丫的debug怎么用，还有项目产品化流程。...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2885048.html</guid>
        <pubDate>Wed, 07 May 2008 09:05:14 GMT</pubDate>
<category>header</category>

        <category>array</category>

        <category>erlang</category>

        <category>解析网络报文</category>

        <category>list_to_bitstring</category>
      </item>

      <item>
        <title>求助</title>
        <link>http://entelechie.ycool.com/post.2881390.html</link>
        <description><![CDATA[失眠，这是很难受的。<br />
但我好像还要惨一点：我已然不会睡懒觉了&hellip;&hellip;<br />
不管头天晚上是10点上床还是次日凌晨1点睡觉，早上总是睡不过7：30。。。<br />
<br />
我已尝试：<br />
1. 提高房间空气质量；<br />
2. 把窗帘拉的严严实实；<br />
3. 头天晚上去健身房发泄；<br />
4. 熬夜<br />
&hellip;&hellip;&hellip;&hellip;<br />
纷纷无效<br />
<br />
以前起得早我还沾沾自喜，现在下午有段时间是实在扛不住了&hellip;&hellip;<br />
各位达人有什么建议不？<br />
不要说早上起来吃安眠药&hellip;&hellip;<br />
<br />
我默默的怀念周末睡到9：30am的感觉&hellip;&hellip;...
]]></description>
        <guid isPermaLink="true">http://entelechie.ycool.com/post.2881390.html</guid>
        <pubDate>Thu, 01 May 2008 10:05:58 GMT</pubDate>

      </item>
    </channel>
  </rss>
