Archive

Archive for April, 2009

Performance of str+str and ‘‘.join()

April 28th, 2009
>>> a = 'a' * 100000
>>> def t(a):
>>>     b = ''
>>>     for i in a:
>>>         b = b + '|' + i
>>>     return b
>>> 
>>> time c = t(a)
>>> time c = '|'.join(a)

In my notebook ( Intel(R) Core(TM)2 CPU T5200 @ 1.60GHz, 1.5G Mem):

The result of time c=t(a):
CPU times: user 2.90 s, sys: 0.00 s, total: 2.90 s
Wall time: 3.07 s

The result of time c = ‘|’.join(a):
CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s
Wall time: 0.01 s

If I changed a from 100000 to 1000000, c=t(a) can’t give me a result in more than 5 minutes while the other one give me the result in 0.09s.

join is much faster than str + str. str + str need to create new strings all the time, but join doesn’t. I guess “join” maybe do something on the memory level.

Developer, Python

“Resource temporarily unavailable” on the whm host

April 4th, 2009

Today, following a document to tune the security of our whm hosting, I enabled “Shell fork bomb protection” in “Security Center”. But I’m 100% sure what I did. Then when I try to run the apache process of the user, the exception “bash: fork Resource temporarily unavailable” raised. It took me a lot of time to find why this happen. Finally I got this document: http://www.eddieoneverything.com/linux/linux-whm-cpanel-resource-temporarily-unavailable.php

It’s because “Shell fork bomb protection” will enable the limitation for each user, the limitation is defined with ulimit command. The default limitation is 100 open files with 20 processes.

Linux

来自 “The Federated States of Micronesia” 的顾客

April 1st, 2009

今天我们站点上出现了个跟国名有关的错误。一个来自”The Federated States of Micronesia”的老兄试图给我们站点留言。我们的IP2Location解析了他的ip并且得到了正确的国家名称”MICRONESIA, FEDERATED STATES OF”。可是我们的数据库country字段的限制是20,最终还是把这位老兄的留言拒之门外了。。。(小国家真不容易,这样也能被拒绝,我估计这老兄一定这么想。)

这让我想起了个问题,不知道世界上最长的国家名称能有多少个字符?
写个blog纪念一下这位老兄的国家吧,也算长见识了。

http://en.wikipedia.org/wiki/Federated_States_of_Micronesia

Python , ,

FireStats icon Powered by FireStats