Now it is also installable via pip.
pip install dioivoAs I said many things changed so some options may not be present and some others were added. In any case it is active development so more feautres and improvements will come.
pip install dioivoAs I said many things changed so some options may not be present and some others were added. In any case it is active development so more feautres and improvements will come.
sudo apt-get install jpegoptim gifsicle pngquant pngcrushOnce you have these compression tools you can start using the compression script. Lets see the options we have.
Use: ./dIb_compress_images <options> <path> Options: -r Revert. Replace all processed images with their backups. -j Compress JPEG files. -p Compress PNG files. -g Compress GIF files. -L Use lossless compression. -q Quiet mode. -c Continue an already started compression. This will convert only not already backuped files. -t <percentage> Only use the converted file if the compression saves more thansize. The files not below will appear as 0% in output. NOTE: If none of -j, -p or -g are specified all of them (-j -p -g) will be used.
root@dgtool:~# pywench --helpMost of the parameters like the SERVER, CONCURRENCY, TOTAL_REQUESTS are probably well known or self-explanatory for you, but you can also see other parameters that are not so common, so let me explain them:
Usage: pywench [options] -s SERVER -u URLS_FILE -c CONCURRENCY -n NUMBER_OF_REQUESTS
Options:
-h, --help show this help message and exit
-s SERVER, --server=SERVER
Server to benchmark. It must include the protocol and
lack of trailing slash. For example:
https://example.com
-u URLS_FILE, --urls=URLS_FILE
File with url's to test. This file must be directly an
access.log file from nginx or apache.'
-c CONCURRENCY, --concurrency=CONCURRENCY
Number of concurrent requests
-n TOTAL_REQUESTS, --number-of-requests=TOTAL_REQUESTS
Number of requests to send to the host.
-m MODE, --mode=MODE Mode can be 'random' or 'sequence'. It defines how the
urls will be chosen from the url's file.
-R REPLACE_PARAMETER, --replace-parameter=REPLACE_PARAMETER
Replace parameter on the URLs that have such
parameter: p.e.: 'user=hackme' will set the parameter
'user' to 'hackme' on all url that have the 'user'
parameter. Can be called several times to make
multiple replacements.
-A AUTH_RULE, --auth=AUTH_RULE
Adds rule for form authentication with cookies.
Syntax:
'METHOD::URL[::param1=value1[::param2=value2]...]'.
For example: POST::http://example.com/login.py::user=r
oot::pass=hackme
-H HTTP_VERSION, --http-version=HTTP_VERSION
Defines which protocol version to use. Use '11' for
HTTP 1.1 and '10' for HTTP 1.0
-l, --live If you enable this flag, you'll be able to see the
realtime plot of the benchmark
root@dgtool:~# /pywench -s "https://www.example.com" -u access_log -c 50 -n 500Well, as you can see, we already have some stats in the output: there are some statistics regarding the timings for ttfb (time to first byte), ttlb (time to last byte) , the fastest and slowest URL and some error code stats.
Requests: 500 Concurrency: 50
[==================================================]
Stopping... DONE
Compiling stats... DONE
Stats (seconds)
min avg max
ttfb 0.15178 7.46277 103.63504
ttlb 0.15299 7.58585 103.63520
Requests per second: 6.591
URL min ttfb: (0.15178) /gallery/now/thumbs/thumbs_img_0401-1024x690.jpg
URL max ttfb: (89.01898) /gallery/then/02_03_2011_0007-2.jpg
URL min ttlb: (0.15336) /gallery/now/thumbs/thumbs_img_0401-1024x690.jpg
URL max ttlb: (90.55633) /gallery/then/02_03_2011_0007-2.jpg
NOTE: These stats are based on the average time (ttfb or ttlb) for each url.
Protocol stats:
HTTP 200: 499 requests (99.80%)
HTTP 404: 1 requests ( 0.20%)
Press ENTER to save data and exit.
[..]Here we have the subdomain balancer-www balanced between two hosts with IP's 258.421.3.182, 258.421.3.183. At the top of these A records we have the "code" that we have to add for the script to know how to proceed. The sintax is simple: ;; BALANCED_AUTOCHECK::<service_port>. The BALANCED_AUTOCHECK part is only a matching pattern and the <service_port> is the port of the service to check. In the above example, we are checking a balancer for an http service, so we are using the port 80.
ftp.example.com 3600 IN A 258.421.3.125
;; BALANCED_AUTOCHECK::80
balancer-www 120 IN A 258.421.3.182
balancer-www 120 IN A 258.421.3.183
balancer-http 3600 IN CNAME balancer-www.example.com.
[..]
Usage: bind9_check_balancer [options] [dns_files]I think it explains quite well how it works but, just in case, here are some examples:
Options:
-h, --help show this help message and exit
-c COMMAND, --command=COMMAND
Command to be executed if changes are made.
(example:'service bind9 restart')
-t TIMEOUT, --timeout=TIMEOUT
Socket timeout for unreachable hosts in seconds.
Default: 5
# Check test.net.hosts and test.com.hosts. If a change is made
# (down/recover detected), exec the command: /etc/init.d/bind9 reload
bind9_check_balancer -c '/etc/init.d/bind9 reload' /etc/named/test.net.hosts /etc/bind/test.com.hosts
# Check all files in /etc/named/zones directory and set a timeout
# of 1 second for connection checks. Also exec: service bind9 reload
bind9_check_balancer -c 'service bind9 reload' /etc/named/zones/*
nginx-X.X.XX/src/http/modules/ngx_http_upstream_ip_hash_module.c
.
However, using this module has several cons:
. In fact, all request from an IPv6 will be redirected to the first backend server (as I understood from the source code). NOTE:
IPv6 addresses are supported starting from versions 1.3.2 and 1.2.2. The version included in last ubuntu (12.10) is 1.1.19 and it is the version I was testing so it lacks of ipv6 support.Colissions as it only uses the 3 first numbers of the IP for the hash. That means that all the ips of the same C-class network range will go to the same backend server.
All users behind a NAT will access to the same backend server.
If you add new backends, all the hashes will change and sessions will be lost.
Because of these problems there are some situations where the balacers will not be fair at all, overloading some nodes while others are idle. For this reason I wondered if it could be possible to balance among servers using other solution than ip_hash.
I found the project nginx-sticky-module which uses cookies for balance among backneds, but it is not integrated into nginx so I had to recompile it which I don't really like for production environments as I prefer to use official packages from the GNU/Linux distribution. So I wondered... would be NGINX so versatile that would let me implement something like this module only using configuration parameters? Guess the answer! There exist a way!
So, now that we are in context, let's start with a little test. Our objective in this example is to use nginx to balance between two backend nodes using cookies. The solution we will implement will work the way it is represented in the following diagram.
server {
listen 80;
location / {
add_header Set-Cookie backend=backend1;
proxy_pass http://localhost:8000/;
proxy_set_header X-Real-IP $remote_addr;
}
}
upstream rrbackend {
server 192.168.122.201;
server 192.168.122.202;
}
map $cookie_backend $sticky_backend {
default bad_gateway;
backend1 192.168.122.201;
backend2 192.168.122.202;
}
server {
listen 80;
location / {
error_page 502 @rrfallback;
proxy_pass http://$sticky_backend$uri;
}
location @rrfallback {
proxy_pass http://rrbackend;
}
}