Archive for May, 2009

Traffic shaping using lighttpd

Wednesday, May 27th, 2009

Now that the server is using lighttpd its become possible to implement traffic shaping, you can even do it per directory which is a nice touch.

$HTTP["url"] =~ “^/photos/” {
connection.kbytes-per-second = 128
}

This limits all urls that start with /photos/ to 128k per second. You can try it on a photo of Queensland Australia that I’ve just uploaded. If you look at the output from wget we can see it in action:

Resolving www.idontplaydarts.com… 80.68.93.53
Connecting to www.idontplaydarts.com|80.68.93.53|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 13858463 (13M) [image/jpeg]
Saving to: `queensland.jpeg’

100%[=============================>] 13,858,463   136K/s   in 1m 46s

2009-05-27 15:44:02 (128 KB/s) – `queensland.jpeg’ saved [13858463/13858463]

And there we have it. Traffic shaping using lighttpd. There are some pitfalls – users can still open multiple connections to your URL using tools such as axel – instructions on installing and using axel on debian can be found on nixCraft

As you can see if we open 4 connections we get 4 times the throughput.

# axel -a -n 4 http://www.idontplaydarts.com/photos/panorama/queensland.jpeg
Initializing download: http://www.idontplaydarts.com/photos/panorama/queensland.jpeg
File size: 13858463 bytes
Opening output file queensland.jpeg.0
Starting download

Connection 3 finished                                                          ]
Connection 2 finished                                                          ]
Connection 0 finished                                                          ]
Connection 1 finished                                                          ]
[100%] [..................................................] [ 524.8KB/s] [00:00]

Downloaded 13.2 megabytes in 25 seconds. (524.79 KB/s)

Lighttpd version 1.5 is going to support a max connections per ip which would be handy if you wanted to prevent people opening multiple connections. Not really that handy for a website but possibly if your serving lots of large static files.

POST causing a 404 error in Wordpress

Saturday, May 23rd, 2009

I’ve just struck a problem while implementing my sudoku solver. It appeared that every time I posted a variable called ’s’ to my page Wordpress would return a 404 – page not found error.

You can post to a page and read the variables in PHP using $_POST – which is good – but you can’t name the variable “s” as this seems to conflict with existing Wordpress functionality.

If your having trouble posting to a wordpress page try renaming your variables.

Moving hosts

Sunday, May 17th, 2009

Today I switched hosts and purchased a virtual server from bytemark. I’ve got to say I really like it. It’s cheap, fast and seems to be quite stable. The new setup is

  • PHP 5.3
  • Mysql 5.1
  • Lighttpd

Which I guess makes it a LLMP stack rather than a LAMP stack. I’ve become a big fan of Lighttpd recently, its pretty much Apache but without the bloat. Its also got some nice traffic shaping features that seem to be lacking from Apache and uses way less resources. Pretty handy when your server only has 256mb of ram.

Moving over to a virtual host has been pretty simple as has migrating the blog from blogspot to wordpress. The new virtual host has given me much greater control over my blog so you can expect to see some new funky code in the near future.