GSoC 2013 Pencil Down :)

GSoC 2013 was really great experience thanks to the Monkey project! 
The time I have spend on the project was very pleasant and helpful for me thanks to the mentors and the community!
 
Last week I spend on writing documentation and check if I miss something to polish.
However I’m planning to continue to supporting the plugin and the project, so if you have any troubles of using it or any suggestions will be appreciated.
 
Thank you !

Weekly update of the Proxy Reverse plugin and some benchmarks

Hi all, 
 
This week I added trace calls to the main proxy file. Now the work of the proxy can be monitored easier. I also made some minor improvements to the code.

I did a lot of performance tests. I used a dual core virtual machine with one monkey configured to work as a proxy (Locking Round Robin used as a balancer) and three slave servers. As you can see the results are pretty good:

Via proxy reverse:

# siege -b -t10S -c1 ‘http://217.18.244.215/‘ > /dev/null
Transactions:                2944 hits
Availability:              100.00 %
Elapsed time:                9.35 secs
Data transferred:            0.12 MB
Response time:                0.00 secs
Transaction rate:          314.87 trans/sec
Throughput:                0.01 MB/sec
Concurrency:                0.96
Successful transactions:        2944
Failed transactions:               0
Longest transaction:            0.16
Shortest transaction:            0.00

# siege -b -t10S -c2 ‘http://217.18.244.215/‘ > /dev/null
Transactions:                6270 hits
Availability:              100.00 %
Elapsed time:                9.89 secs
Data transferred:            0.25 MB
Response time:                0.00 secs
Transaction rate:          633.97 trans/sec
Throughput:                0.02 MB/sec
Concurrency:                1.69
Successful transactions:        6270
Failed transactions:               0
Longest transaction:            0.10
Shortest transaction:            0.00

# siege -b -t10S -c5 ‘http://217.18.244.215/‘ > /dev/null
Transactions:                4591 hits
Availability:              100.00 %
Elapsed time:                9.28 secs
Data transferred:            0.18 MB
Response time:                0.01 secs
Transaction rate:          494.72 trans/sec
Throughput:                0.02 MB/sec
Concurrency:                2.52
Successful transactions:        4591
Failed transactions:               0
Longest transaction:            0.06
Shortest transaction:            0.00

==== ==== ==== ====

Direct:

# siege -b -t10S -c1 ‘http://217.18.244.215:8080/‘ > /dev/null
Transactions:                4594 hits
Availability:              100.00 %
Elapsed time:                9.36 secs
Data transferred:            0.18 MB
Response time:                0.00 secs
Transaction rate:          490.81 trans/sec
Throughput:                0.02 MB/sec
Concurrency:                0.75
Successful transactions:        4594
Failed transactions:               0
Longest transaction:            0.07
Shortest transaction:            0.00

# siege -b -t10S -c2 ‘http://217.18.244.215:8080/‘ > /dev/null
Transactions:                6298 hits
Availability:              100.00 %
Elapsed time:                9.74 secs
Data transferred:            0.25 MB
Response time:                0.00 secs
Transaction rate:          646.61 trans/sec
Throughput:                0.03 MB/sec
Concurrency:                1.90
Successful transactions:        6298
Failed transactions:               0
Longest transaction:            0.13
Shortest transaction:            0.00

# siege -b -t10S -c5 ‘http://217.18.244.215:8080/‘ > /dev/null
Transactions:                6300 hits
Availability:              100.00 %
Elapsed time:                9.76 secs
Data transferred:            0.25 MB
Response time:                0.01 secs
Transaction rate:          645.49 trans/sec
Throughput:                0.03 MB/sec
Concurrency:                3.49
Successful transactions:        6300
Failed transactions:               0
Longest transaction:            0.21
Shortest transaction:            0.00

 
Next week I’m planning to write some more documentation and I will try to compare it with nginx and will write the results.

GSoC 2013 Weekly update: Proxy Reverse – Week 12

It was a busy week mainly related with testing and fixing some serious bugs.
 
I worked mainly to fix two serious bugs. One of them caused infinite looping caused by unhandled events. This led to significant performance decreases when the bug occurred  The other bug was one that I have known about for a while but I just managed to fix it. Sometimes sockets remained open and this led to file descriptor depletion after a while.

I found the reasons behind both bugs and fixed them. Other than that I made some minor code tweaks and used testing tools to make sure everything works and to see whether
performance is good enough. Everything works fine.

Weekly update – week 11

Hi,
This week I worked more on adding new features than bug fixing.
I realized that it is going to be useful to see what is going on with the forwarding server, so I made new feature that provides current status of the proxy plugin.
The proxy reverse status can be turned on by adding StatisticsURL in the configuration file.
This way you are able to set some url like /proxy-status and to check the current slave servers status.
Currently it returns current connections per proxy, offline time and tries to reach the server if has been offline.
Also I made some more tests on the proxy by using the siege tool, it is working fine except that there is some bug with closing fds, some of the connections are not closed.
I’m going to investigate this behavior and make more tests next week.

Monkey Proxy Reverse plugin – UPDATED

Last couple of weeks I’m working on the Proxy Reverse plugin for the Monkey HTTPd during GSoC 2013, so I decided to make a Blog Post that shows some of the use-cases and PREVIEW of the features that will be available.

The main goal of the Proxy Reverse plugin is to forward the http requests from Monkey HTTPd server to backend servers. By using the plugin you are able easily to make a load balancing system of web servers. I have tried to made the configuration of the plugin simple, but powerful enough for achieving complex configurations.

Proxy Reverse plugin in details:

The Proxy Reverse plugin is using Monkey HTTPd API and principals, which means that is non-blocking as possible with less memory consumption in mind.

Initial load of the plugin:

During the initial load, the proxy plugin loads the configuration file and creates the plugin configuration structures ( config.h ), initiates load balancing structures and hooks to the Stage 30 of Monkey HTTPd.

Request life cycle: monkey

1. After the http request is send to the server, Monkey’s internal parser is parsing the request

2. When the request is parsed, is passed to the Proxy Reverse Plugin checks.

3. The plugin is checking Match rules of the Proxy Entries in the configuration file.

4. After the matching proxy is found, the request information and the configuration structure for the matching entry is passed to the load balancer. The Load Balancer is returning host and port for the server that must process the request. If the connection with the slave server can not be established, the Load Balancer is asked for new host until it returns that no more slave servers are available.

5. When the connection to the slave server is established, the proxy starts listening for events. When an event arrives, the proxy handles it – on read events, the pending data is read and stored in buffers; on write events the data stored in the corresponding buffer is written; on close and error events, appropriate actions are taken to free the allocated resources and terminate the connection with the slave server.

Proxy Reverse example configuration:

I will try to explain the configuration settings by simple use case with two proxy configurations. One for static content ( Images, CSS, HTML ) and one proxy entry for the dynamic content (PHP for example).

monkey_balance

Current configuration file:

##
## Proxy-Reverse configuration.
##
## This is example Proxy-Reverse configuration.
## Currently is in proposed (not final) state
##

[PROXY_DEFAULTS]
LoadBalance First-Alive

[PROXY_ENTRY]
ServerList Host4:80 Host5:8080
Match /*.php

[PROXY_ENTRY]
ServerList Host1:80 Host2:80 Host3:80
LoadBalance Round-Robin
Match /*.jpg
Match /*.png
Match /*.css
Match /*.js
Match /*.html

The configuration file consists of PROXY_DEFAULTS and PROXY_ENTRY. PROXY_DEFAULTS contains default values that are copied to each entry if doesn’t have a value. In our example, the first (dynamic) entry is going to use First-Alive load balancing algorithm.

In the current example, if the request contains .php request will be forwarded to Host4 and Host5 that are going to use First-Alive Load Balancing method for serving the response.

If the request is for static content (.jpg, .js .css …) the request will be forwarded to Host1,Host2,Host3 by using Round-Robin load balancing algorithm.

Load Balancing methods description:

Currently the proxy plugin supports several load balancing methods.

Naïve

Simple, non-fair load balancer with almost no overhead.
Connects to the first alive server, starting from server.
For example as a load balancing number might be considered the socket id or sport.
This way first connection will be forwarded to the first server.
If the connection is still open when, second connection will be forwarded to the next server.
If the connection is closed, next one will be forwarded to the first server again.

First-Alive

Simple, non-fair load balancer with almost no overhead.
Connects to the first alive server, starting from 0.

Lockless Round Robin

Simple load balancer with almost no overhead. Race conditions are possible under heavy load, but they will just lead to unfair sharing of the load.
Each consecutive call connects to the next available server. Race conditions may occur since no locking is performed.

Locking Round Robin

Simple load balancer. Race conditions are prevented with mutexes. This adds significant overhead under heavy load.
Each consecutive call connects to the next available server. Race conditions are prevented at the expense of performance.

Least connections

Ensures equal load in most use cases. All servers are traversed to find the one with least connections.
Connects to the server with the least number of connections. Ensures equal load in most use cases but adds significant overhead.

Weighted Round Robin

WRR can be done by entering the same server several times in the Round Robin balancer section.
Example:
[PROXY_ENTRY]
ServerList 127.0.0.1:80 127.0.0.1:81 127.0.0.1:80 127.0.0.1:82 127.0.0.1:80 127.0.0.1:81
LoadBalancer RoundRobin
Match ^/.*
This can be read as:
127.0.0.1:80 weight=3
127.0.0.1:82 weight=1
127.0.0.1:81 weight=2

High-Availability:

The high availability option is used for faster choice of available server when some of the slave servers become offline.
If  the High-Availability option is disabled (by default is enabled), every request will be forwarded to the slave server that is returned from the load balancer.
If some of the slave servers is offline, after the timeout is reached for the connect function, we are picking the next one.
The problem here is that the timeout for the connect takes really long time, there is no point everytime to try connecting to a server that we know from the previous request that is offline.
To handle this, I’m saving the connection states to the slave servers, so when the proxy receive connection, it will know whether the proxy server is on or off, without waiting for connection timeout, it will pick next slave server.
Because there are different use-cases I made 2 options for configuring the High-Availability.

OfflineTimeOut -> Seconds to wait for the next check of the server. This means that this slave server won’t be used for the configured time.
AttemptsCount -> How many attempts to be made, before assuming that the server is offline. After we assume that the server is offline we are trying again after OfflineTimeOut.

Hello Monkey

This is my first Blog post 🙂

I created this Blog mainly because of writing for my work on the Monkey HTTPD Project, but who knows I may like blogging 🙂