Migrated my busy PHP/Drupal website last night from one VPS hosting provider to another. In the process I am also upgrading the operating system from Debian 5 “Lenny” to Ubuntu 10.04 “Lucid Lynx”. A bad move especially when I have not tested the new platform thoroughly — with new stacks such as MySQL 5.1 (from MySQL 5.0), PHP 5.3 (from PHP 5.2) and Python 2.6 (Python 2.5, as part of the service was written in Tornado). Ended up spending the morning picking up broken pieces.

I am also using Memcached for various caching, and to share variables between my PHP 5 Drupal setup and my Tornado server. Move from Debian 5 to Ubuntu 10.04 means moving from Memcached 1.2.2 to 1.4.2, which supports new UDP and binary protocol. Right after turning the service back on I am getting errors such as this every 1-2 seconds:

MemcachePool::get(): Server localhost (tcp 11211, udp 0) failed with: Network timeout (0) in /var/www/my-script.php on line 123

New server is running Ubuntu 10.04 x86_64 on Xen HVM, with 6GB of memory and access to 6 cores of Xeon E5620, which should be significantly faster than the host I migrated from. I could not figure out the actual cause (too many opinions and “fixes” from Google that do not work). However it turns out with PHP memcache module, using pconnect() rather than connect() almost eliminate the issue.

  $memcache = new Memcache;
- $memcache->connect('localhost', 11211) or die('Cannot connect to memcached');
+ $memcache->pconnect('localhost', 11211) or die('Cannot connect to memcached');

It’s not completely eliminating the issue as I am still getting around one time out every 3-4 hours. It’s not heavy usage either — only around 50 get/set commands per second.