Start by installing Raspbian on an SD card, and changing the default settings. You can set up the operating system on a hard disk if you need your server to run as fast as possible, but this isn't necessary. I'm just using SD cards in my servers.
I'm going to give each server a static IP address. I could use DHCP, but then it would be difficult to tell which server has which IP address. There are only four servers, and I only have to set the IP address once for each server.
Open the interfaces file with this command:
On the line that starts with 'iface eth0', the word 'dhcp' needs to be replaced with the word 'static'. You also need to add an IP address and netmask. The interfaces file should look like this:
To save changes, press control-o and press return. To close the file, press control-x.
I'm using Nginx because it has a reputation for serving static content quickly. Pyplate's page caching mechanism generates static versions of pages, so Pyplate sites are mostly made of static content. Nginx only serves static files, so it must be used with a WSGI server.
uWSGI is a server which runs in parallel with Nginx. Any request that Nginx can't handle by serving a static file is passed to the uWSGI server. The uWSGI server executes the main script in Pyplate, and returns the result to Nginx.
Install Nginx and some packages needed by uWSGI and Pyplate:
Download and run the Pyplate installation script for Nginx:
Edit the webserver's crontab file:
Paste the following command at the end of the file, save the changes, and close the file.
In many Linux distributions the nano editor is used to edit crontab files. To save changes, press control-o and press return. To close the file, press control-x.
Back up Nginx's default config file:
Replace it with the sample config file
Make sure that you've made a note of the password generated by the installation script, and then delete this file:
Restart your server
Login, and change the password to something more memorable than the random string used as a temporary password.
Note that Pyplate can also be installed with Apache or a simple Python webserver.
I did a few simple tests to improve performance. I did these tests using an ethernet connection rather than wifi. I used this command to bombard my Banana Pi with HTTP GET requests:
When I tried using more than 350 concurrent users, Nginx started dropping requests. With no tuning, Nginx handles 407.2 transactions per second.
Linux sets a limit on the number of file descriptors that a process can open. There is a hard limit which can be set by root, and there is a soft limit that can be adjusted by users. Users can't increase the soft limit beyond the hard limit.
You can find your server's hard limit by typing this command:
Open /etc/nginx/nginx.conf in a text editor and find worker_connections. Increase this value to 1024 (or whatever number is printed out by the ulimit command). When I did this, I ran siege again, and this time the server handled 426.37 transactions per second.
I reduced the number of Nginx worker threads from 4 (default) to 2. Nginx only needs one worker process for each CPU, and adding extra processes doesn't increase performance. Extra Nginx worker processes are generally considered to be a harmless waste of memory, however, when I retested the server's performance with only two worker processes, I found that getting rid of the spare processes improved performance. This time the server handled 443.96 transactions per second.
It's also recommended that you reduce the keepalive_timeout value from 65 to 30, although this didn't make any noticeable difference to performance.
See also: Install Pyplate.
Share this page: