Friday, September 26, 2008

jQuery.com down or super slow

Anyone knows a downloadable documentation for jQuery. Their site is so slow that makes referencing impossible. This is an recurring issue that has happened for quite a few months. Is the traffic too much for them to handle?

Labels: ,

Thursday, September 25, 2008

jQuery not selecting nested elements

For a jQuery newbie, I was unsure how to only select the TR's of the main table and not TR's within sub-tables. Tried this that (children(), siblings()) and a bunch of selectors and found out the easy way ('#mytable > tbody > tr') How easy! :)

Labels:

Tuesday, September 23, 2008

Improve security for apc.php

If you're running APC with PHP, you have the option to download apc.php to view, monitor the usage/stats. However, the default authentication is very open. Without any credential, anyone can view the running stats and also the cached filenames (a simple search on "APC INFO" will show some site running APC). The login is to view per-directory file caching. So if you want to require login credential on ALL access change this code: to this:

Labels: ,

Sunday, September 21, 2008

pecl and memory limit error

If you run "pecl install [something]" and get this error: "Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate xxx bytes)", you want to change "/usr/bin/pecl" (or run "locate pecl" to see where it is) and specify a larger memory limit.
#!/bin/sh
exec /usr/bin/php -C -n -q -d include_path=/usr/share/pear \
    -d output_buffering=1 /usr/share/pear/peclcmd.php "$@"
becomes
#!/bin/sh
exec /usr/bin/php -C -n -q -d include_path=/usr/share/pear \
    -d memory_limit=16M -d output_buffering=1 /usr/share/pear/peclcmd.php "$@"

Labels:

Friday, September 19, 2008

ip_conntrack and dropped packets

For busy servers, ip_conntrack can fill up quickly and must be monitored or you will get intermittent packet drops. Check var/log/messages for these error messages. Couple values can be adjusted to the kernel:
more /proc/sys/net/ipv4/netfilter/ip_conntrack_count
more /proc/sys/net/ipv4/netfilter/ip_conntrack_max
=> count should be less than max, if it's near the maximum value, increase max

more /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established
=> default 5 days, might want to lower it

echo 0 > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_loose

Labels:

Thursday, September 18, 2008

mod_deflate bug

Hmm, another day, another bug: #33499. This time it is mod_deflate and PHP don't play well together. PHP makes a GIF/JPG file and yet mod_deflate still compress it. Solution: use mod_filter (which only available from 2.1), or disable Apache's compression for PHP files and let PHP do the compression via ob_start('ob_gzhandler');

Labels:

Wednesday, September 17, 2008

Get network stats for RRD graphing

This snippet displays Active, Passive and Established connections reported by "netstat --statistics" for saving into RRD or other monitoring tools.

Labels:

Tuesday, September 16, 2008

Apache versus lighttpd

Both run on the same server: Apache/2.0.59 (port 80) & lighttpd 1.4.19 (port 8080). 2 tests: dynamic & static files. To make things a little realistic, it's from a EU client to a US server.

Serving a dynamic file

eu$ ab -n 1000 -c 10 "http://us.server/run-some-sql.php"
Server Software:        Apache
Server Port:            80
Document Length:        824 bytes
Time taken for tests:   36.51463 seconds
Total transferred:      1213118 bytes
HTML transferred:       847886 bytes
Requests per second:    27.74 [#/sec] (mean)
Time per request:       360.515 [ms] (mean)
Time per request:       36.051 [ms] (mean, across all concurrent requests)
Transfer rate:          32.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      158  158   0.3    158     162
Processing:   174  200  26.4    191     340
Waiting:      173  199  26.3    191     340
Total:        332  358  26.4    349     498
Server Software:        lighttpd/1.4.19
Server Port:            8080
Document Length:        921 bytes
Time taken for tests:   35.406200 seconds
Total transferred:      1202655 bytes
HTML transferred:       857071 bytes
Requests per second:    28.24 [#/sec] (mean)
Time per request:       354.062 [ms] (mean)
Time per request:       35.406 [ms] (mean, across all concurrent requests)
Transfer rate:          33.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      158  158   0.6    158     167
Processing:   172  193  29.0    183     383
Waiting:      172  192  29.0    183     383
Total:        330  351  29.1    341     541
Apache: 27.74 requests/sec
Lighttpd 28.24 requests/sec

Serving a static file

eu$ ab -n 1000 -c 10 "http://us.server/img/some-image.gif"
Server Software:        Apache
Server Port:            80
Document Length:        14781 bytes
Time taken for tests:   63.858434 seconds
Total transferred:      15060000 bytes
HTML transferred:       14781000 bytes
Requests per second:    15.66 [#/sec] (mean)
Time per request:       638.584 [ms] (mean)
Time per request:       63.858 [ms] (mean, across all concurrent requests)
Transfer rate:          230.31 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      157  158   0.5    158     164
Processing:   476  478   4.6    478     549
Waiting:      158  159   4.0    159     228
Total:        634  636   4.6    636     707
Server Software:        lighttp/1.4.19
Server Port:            8080
Document Length:        14781 bytes
Time taken for tests:   63.736261 seconds
Total transferred:      14992000 bytes
HTML transferred:       14781000 bytes
Requests per second:    15.69 [#/sec] (mean)
Time per request:       637.363 [ms] (mean)
Time per request:       63.736 [ms] (mean, across all concurrent requests)
Transfer rate:          229.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      157  158   0.4    158     160
Processing:   476  478   2.2    478     491
Waiting:      158  158   1.5    159     166
Total:        634  636   2.3    636     649
Apache 15.66 requests/sec
Lighttpd 15.69 requests/sec
Apache is very decent when there is a low concurrency level (about 10-20). When taken into account the stability, features, modules, it's an excellent choice. Lighttpd under high load although can perform very well, it does suffer from an issue with PHP (current with 1.4.19 and 5.1.6), its backend fast-cgi became overloaded and gave out 500 errors to clients. Bad lighty, or bad PHP! Hope they got it fixed in 1.5 or some future version of PHP

Labels:

Counting TIME_WAIT with netstat

# netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
Sample Output:

     15 CLOSING
     26 ESTABLISHED
     31 FIN_WAIT1
      7 FIN_WAIT2
     14 LAST_ACK
      2 LISTEN
     24 SYN_RECV
   2428 TIME_WAIT

Labels:

Wednesday, September 10, 2008

Qcache_not_cached should be small

If not, you're wasting overhead on checking and invalidating the query cache, for a large/busy query cache, it gets more expensive. Thus, the lesson is to know which query should not be cached and explicitly use "SELECT SQL_NO_CACHE ..." in your SQL statement. It means tables with many UPDATES/INSERTS should not use query caching.

Labels:

Tuesday, September 09, 2008

What happens when you do "rm -rf /*"

Just for the fun of it. Here is what happens:
[root@s10 ~]# cd /
[root@s10 /]# dir
bin   dev  initrd  lost+found  misc  opt   sbin     srv  tmp  var
boot  etc  lib     media       mnt   proc  selinux  sys  usr
[root@s10 /]# rm -rf *
rm: cannot remove directory `boot': Device or resource busy
rm: cannot remove directory `dev/shm': Device or resource busy
rm: cannot remove `dev/pts/1': Operation not permitted
rm: `proc/asound/ICH' changed dev/ino: Operation not permitted
[root@s10 /]#
[root@s10 /]# dir
-bash: /usr/bin/dir: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
[root@s10 /]# ll
-bash: ls: command not found
[root@s10 /]# reboot
-bash: /sbin/reboot: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
Since the processes are still running, SSH still accept connections, but cannot sign in, can't run anything either. Was it fun?!

Labels:

Sunday, September 07, 2008

Firefox Performance Tips

Check memory cache usage

about:cache?device=memory Reference

Disable disk cache

config:about => browser.cache.memory and browser.cache.disk

Labels:

SHOW COLUMNS FROM MyDatabase.MyTable

That operation will always require a disk read, which is rather expensive, especially for larger tables. For example, for a 500MB table in my test, it takes 0.23 seconds just for this query. I thought the table schema should not depend on its size. Guess there is something more technical than my basic understanding.

Labels:

Saturday, September 06, 2008

Related keywords & spelling suggestion API

Google Toolbar Auto Complete
Replace your own "q=keywords": http://google.com/complete/search?output=toolbar&q=Ad+Server
Google SOAP Search API
http://scholar.google.com/apis/reference.html#1_3
Yahoo Related Keywords API
http://developer.yahoo.com/search/web/V1/relatedSuggestion.html
Yahoo Spelling Suggestion API
http://developer.yahoo.com/search/web/V1/spellingSuggestion.html

Labels: