|
| 1 | +==================================== |
| 2 | +Configuring a local test environment |
| 3 | +==================================== |
| 4 | + |
| 5 | +tl;dr; |
| 6 | +====== |
| 7 | + |
| 8 | +This text explains how to configure *nginx* and *vaurien* to build |
| 9 | +a local mirror of the data to test the Wikipedia Picture of the Day |
| 10 | +examples while saving network bandwidth and introducing controlled |
| 11 | +delays and errors, thanks to the *vaurien* proxy. |
| 12 | + |
| 13 | + |
| 14 | +Rationale and overview |
| 15 | +====================== |
| 16 | + |
| 17 | +The Wikipedia Picture of the Day examples are designed to demonstrate |
| 18 | +the performance of different approaches to finding and downloading |
| 19 | +images from the Wikipedia. However, we don't want to hit the Wikipedia |
| 20 | +with multiple requests per second while testing, and we want to be |
| 21 | +able to simulate high latency and random network errors. |
| 22 | + |
| 23 | +For this setup I chose *nginx* as the HTTP server because it is very |
| 24 | +fast and easy to configure, and the *vaurien* proxy because it was |
| 25 | +designed by Mozilla to introduce delays and network errors for testing. |
| 26 | + |
| 27 | +The initial fixture data, ``docroot.zip``, contains a directory |
| 28 | +``docroot/Template-POTD/`` with 1096 small text files, each consisting |
| 29 | +of an HTML fragment (just a ``src="..."`` attribute) or an error message |
| 30 | +(for days when no picture was published, like 2013-09-12). These files |
| 31 | +correspond to every day of the years 2012, 2013 and 2014. The year 2012 |
| 32 | +was a leap year, that's why there are 1096 files and not 1095. |
| 33 | + |
| 34 | +Once these files are unpacked to the ``docroot/Template-POTD`` directory |
| 35 | +and *nginx* is configured, the ``build_fixture.py`` script can fetch the |
| 36 | +actual images from the Wikipedia for local storage in the directory |
| 37 | +``docroot/wikimedia/``. |
| 38 | + |
| 39 | +When that is done you can configure *nginx* and *vaurien* to experiment |
| 40 | +with the ``daypicts*.py``examples without hitting the network. |
| 41 | +
|
| 42 | +
|
| 43 | +Instructions |
| 44 | +============ |
| 45 | +
|
| 46 | +1. Unpack data |
| 47 | +-------------- |
| 48 | +
|
| 49 | +Unpack the initial data and verify that 1096 files were created:: |
| 50 | +
|
| 51 | + $ unzip docroot.zip |
| 52 | + ... many lines omitted... |
| 53 | + inflating: docroot/Template-POTD/2014-12-29 |
| 54 | + inflating: docroot/Template-POTD/2014-12-30 |
| 55 | + inflating: docroot/Template-POTD/2014-12-31 |
| 56 | + $ ls docroot/Template-POTD/ | wc -w |
| 57 | + 1096 |
| 58 | +
|
| 59 | +
|
| 60 | +2. Install *nginx* |
| 61 | +------------------ |
| 62 | +
|
| 63 | +Download and install *nginx*. I used version 1.6.2 -- the latest |
| 64 | +stable version as I write this. |
| 65 | +
|
| 66 | +- Download page: http://nginx.org/en/download.html |
| 67 | +
|
| 68 | +- Beginner's guide: http://nginx.org/en/docs/beginners_guide.html |
| 69 | +
|
| 70 | +
|
| 71 | +3. Configure *nginx* |
| 72 | +-------------------- |
| 73 | +
|
| 74 | +Edit the the ``nginx.conf`` file to set the port and document root. |
| 75 | +The file is usually found in ``/usr/local/nginx/conf``, ``/etc/nginx``, |
| 76 | +or ``/usr/local/etc/nginx``. |
| 77 | + |
| 78 | +Most of the content in ``nginx.conf`` is within a block labeled ``http`` |
| 79 | +and enclosed in curly braces. Within that block there can be multiple |
| 80 | +blocks labeled ``server``. Add another ``server`` block like this one:: |
| 81 | + |
| 82 | + server { |
| 83 | + listen 8001; |
| 84 | + |
| 85 | + location / { |
| 86 | + root /full-path-to-your-directory/fixture/docroot; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +http://localhost:8001/Template-POTD/2014-01-01 |
0 commit comments