PPL30 Day 18: Nginx
Many of you have already used Nginx. I apologize if this post is thus quite a bore – as a friend recently said, “It’s just a web server, man.” Nonetheless, it’s a bit different in that it’s event-driven, and built by these guys:
To learn Nginx, I logged into a server I’ve been using for CI. I’m replacing Apache + Passenger with Nginx + Passenger.
This is part of the Peer Pressure Learning 30 series. To learn more about what in the hell that means, see the intro to the series, A Good Time To Learn.
Installation
It’s a bit more complicated today.
sudo gem install passenger
passenger-install-nginx-module
Barely. That’s about it. The Passenger installation takes care of downloading, compiling, and most of the configuring. I just modified the directory for the virtual host, and added some basic authentication, and I had my CI server running!
Resources
Nginx Wiki
Though the Nginx Wiki lacks all of the documentation that Apache has gathered over the years, it’s definitely a good place to start.
Passenger User Guide
Passenger has a well-written user guide to go with its well written installation scripts. I love it. Usually, if I have an issue with Passenger, I just go straight to the user guide. This is remarkable because my process for every other thing that gives me trouble is to go straight to Google.
What I Think I Now Know
Nginx is an event-based server written in C. If “event-based” sounds familiar, Node.js is an event-based Javascript framework for building scalable servers (among other things), and I did it yesterday. Event-based is cool with all the hip nerds. Hipster nerds. Hipsnerds. … And for good reason!
There are several benchmarks that tend to show Nginx significantly out-performaing Apache. The general consensus seems to be that much of this can be attributed to Nginx using an event-driven method, keeping resource use quite low.
Getting it set up was incredibly easy, though that may be due mostly to Passenger’s help. Did I get Apache replaced by Nginx successfully? Yup. *snap*! Done.
So, I thought I’d do a quick benchmark of my own. This is running against an installation of Signal, an absolutely unoptimized Rails app. It’s hosted on a Linode box that hasn’t be restarted since they bumped the RAM from ~368 to 512. (Oops.)
# Command
httperf --server scruffy --uri / --num-conns 200
# Apache + Passenger
Reply rate [replies/s]: min 7.6 avg 7.7 max 7.8 stddev 0.1 (5 samples)
# Nginx + Passenger
Reply rate [replies/s]: min 8.4 avg 8.5 max 8.6 stddev 0.1 (4 samples)
Well, I wouldn’t call that definitive. I’m not sure I’m even willing to call it something. I wish I had pretty graphs for you, but autobench
is upset with me, and gnuplot
is pissed at autobench
, and httperf
would rather they all just leave him alone. It’s been a trying night.
One of the more interesting things about Nginx is the scripting you can do from within a configuration file. If you’re brave, check out this presentation that includes retrieving data from Memcached, or even from MySQL!
I know many of you use Nginx frequently. What do you like about it?
It’s the weekend (almost? … Thursday night is close enough)! A busy one! A long one! I must persevere. I’ll tell you the schedule ahead of time: Friday => Unicorn, Saturday => MooTools, Sunday => LowPro. Keep the pressure on Tim Harvey and I this weekend. It’s going to be a challenge. Who decided this experiment was going to span a holiday?