web.py sucks

web.py might be famous, but it really sucks in performance.

I tried code.py from tutorial and was shocked. The `ab -c 10 -n 1000` benchmark shows code.py can only handle 200 request per second. (CherryPy is about 600 r/s). And in order to boost performance, I also tried mod_wsgi with web.py, the perfomance gain in 20% ~ 30%.

The API design of web.py is not beautiful and even ugly, how stupid it maps URL into a class but not a callable object and force people to write GET, POST functions. It’s not the OO way in which CherryPy code looks much better.

Finally, my suggestion is to get rid of web.py as soon as possible, even in small project. Try mod_wsgi instead if in hurry.

BTW, mod_wsgi is quite excellent, much better than mod_python.

Notes on Python Socket Module

I was surprised to see how Python implements socket module in its C level today. Python doesn’t use real connect(2), it implements internal_connect via poll(2). I think it caused by GIL, you can find lots of Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS macros around the code to ensure the code runs correctly in multi-threads mode.

How to terminate Thread in Python?

The safest way is using threading.Event to avoid sync problem.

import threading
 
class TestThread(threading.Thread):
 
    def __init__(self):
        self.stopEvent = threading.Event()
 
    def run(self):
        while not self.stopEvent.isSet():
            pass
 
    def stop(self):
        self.stopEvent.set()

玩了下 syslog

写了一个日志模块,Java 的经验告诉我直接用 logging 模块要比自己依赖特定的 logger 没快要好。不过这回碰到 syslog,我就错了。

Python 的标准 logging 模块的确不如直接用 syslog 模块好使。syslog 的接口很简单,后面的工作就交给自己去配置 syslog.conf 了,相当的好用,想存哪存哪,还能自己配置过滤不同级别的日志。

PS:朱同学说 BSD 下的 syslog 相当优秀,Linux 下的就是一托屎了(据说记一下日志需要 25ms :O),BSD 下那就是快的你根本没什么感觉。

Komodo Edit 更新到了 5.0

我不是一个 TextMate 的粉丝,我更喜欢 Komodo Edit,最近出了 5.0 总算接近原生界面了,应该是更新了 Firefox 3.x 用新的 XUL 引擎。

下面来个截图:
Komodo Edit 5

三个月的流水账

总算又来更新了,早就知道好久没写了,不过猛一看最新的一篇居然是 7 月 9 号,现在都已经 11 月了啊,时间过得太快了。

7 月份去了中软,头一个月挺闲的,天天无所事事。第二个月开始项目来了,但不小心把手弄伤了,打了两个月石膏上班,练就了灵活的左手。虽然很多人劝我别去中软,不过我还是硬着头皮去了,当然了,早就开始后悔了。不过嘛,也有一定的无奈,毕竟上半年花了大部分精力做的东西没有预期的效果。一份正式的工作至少能把状态调整一下,于是就跟着 Martin 去了。

不过去了外包公司,至少让我改变了一个看法。以前总觉得这些人都是实在无奈才选择的外包公司,然后就糊里糊涂的干下去。但现实却不是这样的,为了降低成本,中软和其他此类公司一定会瞄准毕业生,每年要招收大量的学生。但是很多人还是挺喜欢学习的,并且还是很敬业的,天天下了班都不走,在看技术文档。但是日子一长,写代码除了熟练一点之外并没有学会其他的东西,因为他们的所学无非是建立在前人写好的代码基础上,而且质量普遍不高。当然了,这种公司里面的领导动不动就把 CMM 之类的工程学放嘴边,搞的很有学问的样子,就算是 PM 都要摆姿态,不和底下的普通员工走的太近,实在不是一个好地方……