Category: 小小草

IT 技术领域学海无涯。其实任何领域都学海无涯,无非 IT 发展太快了,让我有更多嘘唏。希望我掌握的技术有如小小草,虽然渺小,却有旺盛的生命力。

  • Download Magento via ssh

    wget http://www.magentocommerce.com/downloads/assets/1.3.2.3/magento-1.3.2.3.tar.gz

    If you download Magento from the download page, you see this link http://www.magentocommerce.com/getmagento/1.3.2.3/magento-1.3.2.3.tar.gz. But you can not use wget http://www.magentocommerce.com/getmagento/1.3.2.3/magento-1.3.2.3.tar.gz without specifying referrer. Some technique of anti hot link is implemented there.

  • Check if the port is in use

    netstat -nap | grep 8080

  • mysql_update

    When using phpmyadmin, after select a database, then click on Privileges, you might run into a error saying

    Unknown column ‘Event_priv’ in ‘field list’

    The error will go after you run

    mysql_upgrade

    in command line.

    I feel mysql query speed is improved after running “mysql_update”.

  • Connection speed of sourceforge

    Connection speed of the Godaddy server is generally slower than the 1&1 server. It was test proven from Europe and China. However, when connecting to downloads.sourceforge.net, Godaddy is faster.

    The Godaddy server automatically chooses the mirror site softlayer.dl.sourceforge.net, and the average speed is 8.55M/s. The 1&1 server chooses dfn.dl.sourceforge.net, and the speed is 70K/s. When I force the 1&1 server to download from softlayer.dl.sourceforge.net, the speed does not improve. It is slower even than I download from my PC via ADSL.

    I do not know why there is such a big difference in connection speed from different locations.

  • Gracefully restart Nginx

    Follow these 3 steps to gracefully stop and start Nginx without losing any queries. It works like a charm.

    1. Test new configuration is correct
      nginx -t
    2. Find the Pid
      ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
    3. And kill it. Meanwhile, new configuration is already effective.
      kill -HUP ????
      (replace ???? with the Pid given in step 2)
  • Use Inkscape to open .ai and .cdr files

    Occasionally I need to open .ai (Adobe Illustrator) and .cdr (Coreldraw) files on Fedora, and I found Inkscape is good enough for me. I won’t edit these files so I don’t know Inkscape full capacity.

  • Speed bottleneck of the web server

    非常典型的多层架构:
    第一层 Nginx
    第二层 php fastcgi
    第三层 memcached
    第四层 MySql

    Apache 有个 mod_php,相当于合并了第一层和第二层,Nginx 没有 module for php,这不是什么问题,分层更利于扩展。第三层的加入完全是为了减轻数据库压力,提高性能。目前第2,3,4层之间的优化差不多到极限了(或者说到我能力的极限了),但第1,2层之间尚有潜力可挖。

    not_in_use.php 和 not_in_use.html 都是一个静态文件,没有数据库操作。但 php 文件必须由 Nginx 经由 php fastcgi (使用 unix socket)产生,html 则由 Nginx 直接访问文件系统,就单因素分析,php fastcgi 是普通文件系统速度的34%,所以要想办法绕开 php fastcgi。以下测试在数据中心主机上直接运行 ApacheBench。

    测试一:
    $ ab -kc 100 -n 500 http://magento/not_in_use.php
    This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Copyright 2006 The Apache Software Foundation, http://www.apache.org/

    Benchmarking magento (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Finished 500 requests

    Server Software: nginx/0.6.36
    Server Hostname: magento
    Server Port: 80

    Document Path: /not_in_use.php
    Document Length: 7686 bytes

    Concurrency Level: 100
    Time taken for tests: 0.336355 seconds
    Complete requests: 500
    Failed requests: 0
    Write errors: 0
    Keep-Alive requests: 0
    Total transferred: 4089329 bytes
    HTML transferred: 4004406 bytes
    Requests per second: 1486.52 [#/sec] (mean)
    Time per request: 67.271 [ms] (mean)
    Time per request: 0.673 [ms] (mean, across all concurrent requests)
    Transfer rate: 11871.39 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 11 17.8 3 58
    Processing: 13 49 17.9 50 94
    Waiting: 3 45 18.8 46 88
    Total: 25 60 14.2 61 94

    Percentage of the requests served within a certain time (ms)
    50% 61
    66% 70
    75% 72
    80% 74
    90% 79
    95% 80
    98% 84
    99% 86
    100% 94 (longest request)

    =======================================================
    测试二:
    $ ab -kc 100 -n 500 http://magento/not_in_use.html
    This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Copyright 2006 The Apache Software Foundation, http://www.apache.org/

    Benchmarking magento (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Finished 500 requests

    Server Software: nginx/0.6.36
    Server Hostname: magento
    Server Port: 80

    Document Path: /not_in_use.html
    Document Length: 7686 bytes

    Concurrency Level: 100
    Time taken for tests: 0.115725 seconds
    Complete requests: 500
    Failed requests: 0
    Write errors: 0
    Keep-Alive requests: 500
    Total transferred: 3959000 bytes
    HTML transferred: 3843000 bytes
    Requests per second: 4320.59 [#/sec] (mean)
    Time per request: 23.145 [ms] (mean)
    Time per request: 0.231 [ms] (mean, across all concurrent requests)
    Transfer rate: 33406.78 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 3 7.3 0 22
    Processing: 7 17 4.1 18 23
    Waiting: 7 16 4.0 17 23
    Total: 7 20 9.9 18 41

    Percentage of the requests served within a certain time (ms)
    50% 18
    66% 20
    75% 22
    80% 37
    90% 39
    95% 40
    98% 41
    99% 41
    100% 41 (longest request)

  • Fedora update made my system unbootable

    今天 Fedora 的一个更新后提示我 logout and relogin,结果我 logout 后死机。重启,进度条到100%后还是死机。

    幸好我注意到这个更新是关于 ntfs 的,马上把 /etc/fstab 里我添加的几个条目注释掉,系统又可以启动了。我再细察了/etc/fstab,关于 cifs 的加载,原先写得不是很规范,缺少 sec=none 参数,造成 Fedora 更新后不能启动。

  • Run opentaps as a service

    为了让 Opentaps 在系统启动后自动启动,我在 /etc/rc.d/rc.local 里添了一行

    /path/to/opentaps/startofbiz.sh

    在 Opentaps 1.0.4 版之前用这个方法启动 Opentaps 没发现大的问题,但 1.0.4 版运行 startofbiz.sh 的当前目录必须为 opentaps 的目录,不能再用上述办法启用 Opentaps。再说上述办法并不是正统的以 service 运行 Opentaps,所以我又重新寻找一个能让 Opentaps 自启动的办法。其实也很简单:

    1. 适当编辑 rc.ofbiz 的参数 (rc.ofbiz 似乎是在 DOS 下写就的,我用了一次 dos2unix 才让它运行起来)
    2. cp /path/to/opentaps/rc.ofbiz /etc/init.d/ofbiz
    3. chmod 755 /etc/init.d/ofbiz
    4. chkconfig --add ofbiz
    5. chkconfig --level 235 ofbiz on
    6. service ofbiz start
  • Tough Parallels Plesk

    Parallels Plesk 对我来说是鸡肋。1&1 送了这玩意一年的许用证,一年以后我还用 1&1 吗?我如果用了 Parallels Plesk 就怕象吃鸦片上瘾,以后如果离开 1&1,别人家如果不送 Parallels Plesk 就要花钱买,那时我会觉得很懊恼。

    1&1 既然送了 Parallels Plesk,我也在 Parallels Plesk Panel 里转了一圈,觉得它算是一款好的商业软件,只不过不对我的胃口罢了。正因为如此,我没删 Parallels Plesk,只是将 psa service 停止了。

    如此相安无事过了几个星期,今天突然发现 opentaps 不能启动了。一查,8443 端口被占用了,我马上想到是 Parallels Plesk 又复活了,难道 psa 还有一个守护进程?Parallels Plesk 这么设计大概为了保证 Panel 的 up time,但有点病毒作风,再加我也搞不清它的机理,看来要把它删了一了百了。