Category Archives: GSoC

Virtual Hosting and its support by Monkey HTTP server

Virtual hosting is allowing one server to represent different machines. This basically for supporting multiple host names on one server. For example, there may be two websites – example.com and example.org that may be having the same IP address. For the two websites, even though their information is hosted on the same server, it is maintained in different directories.

There are two types of virtual hosting at the moment:
1. Name-based virtual hosting
2. IP based virtual hosting

virtual-host-3

What is its advantage ?

The advantage of virtual hosting is that a server shares its resources with multiple websites have the site content on the same server. It shares its resources like processor cycles and memory, etc. with different servers. In a server, virtual hosting is seen as a method to share the server content between different domains.

How to configure Monkey server with two virtual host ?

The following are the steps to be followed while configuring support for virtual hosts in Monkey server.

1. You need to change the /etc/hosts file to add multiple hosts to the same IP address. For example,

 127.0.0.1 monkey1
 127.0.0.1 monkey2

So now we have two virtual hosts assigned to the same IP address.

2. Now both of these servers will have different directories under which their resources are shared, in monkey/htdocs/ directory. (monkey/htdocs/monkey1 and monkey/htdocs/monkey2)

3. Each will also need configuration file that states the Document root folder where its resources have been located and its ServerName. The example of a configuration file for one of these servers is as follows:

[HOST]
    Documentroot /home/savita/monkey/htdocs/monkey1
    ServerName monkey1

4. Now on typing the URL: https://monkey1:2001/monkey1/amma1.jpg this particular image which was stored in monkey1 folder is displayed on the browser. For virtual host monkey2, this resource will be present in monkey2/ directory. So if you were to type in the URL space, https://monkey2:2001/monkey2/amma2.jpg, the image that was placed in that location is obtained and displayed on the browser.

The process of having different virtual hosts. In each HTTP request, the host name and the resource URI are mentioned. Now, it checks if the particular virtual host exists and within the virtual host, a particular resource exists or not. If not, then an error is returned.

Sharing file descriptors among different requests :

Monkey follows a special method of sharing file descriptors among different requests that come to the same virtual host so that it avoids opening numerable file descriptors at the same time. This is called File Descriptor Table (FDT).

For each worker or thread, a hash table is maintained with 64 entries and each of these maintains a subarray of 8 chains. So when a request arrives at one of the virtual hosts, it hashes the name of the resource being requested (which can be obtained from the HTTP header) and looks up if the file descriptor for this resource is already present in the hash table for that particular worker. If present, instead of opening another file descriptor for the same file, the already open file descriptor is used. The number of users using that particular file descriptor is incremented. If a particular request stops using a particular file, it checks if the number of users of the file descriptor is greater than zero or not. If it is greater than 0, then a message is just returned that states that the file descriptor is still being used. Else, if the number of users of the file descriptor is zero, then the file descriptor is closed. <using close (2) system call>.

This improves the performance of the monkey server.

Under normal conditions, different virtual hosts do not share data with each other. The main reason that the sharing of file descriptors takes place between different requests within the same virtual host and not among different virtual hosts is to enable or disable such an option for various virtual hosts.

Reference :

  1. Picture Courtesy : http://www.thegeekstuff.com/2011/07/apache-virtual-host/
  2. https://github.com/monkey/monkey/commit/4efbc11bafeb56fbe2b4f0f6925671630ce84125

Monkey HTTP server

Monkey server is a lightweight Http server for Linux, written completely in C. It places immense importance on performance and consumes very less memory and for this reason, it is also favourable for embedded devices. It focuses strongly on Linux, the reason for this being that the server depends on the Linux kernel to perform operations that improve the performance of the server. It is HTTP/1.1 compliant. Some of the important features of the server are:

  1. Multi threaded architecture to handle incoming requests from clients: Each thread has the capability to handle 1000 client requests.
  2. Monkey server uses an event driven model to handle requests coming to a thread at the same time.
  3. It supports virtual hosting.
  4. Provides support for IPv4 and IPv6.

The major components of the monkey server are scheduler, threads, plugins. The monkey server has a variety of plugins that serve various functionalities.

  1. Auth – for basic HTTP authentication for users of different virtual hosts of the server.
  2. CGI – helps in enabling CGI support for monkey server.
  3. Cheetah – command line for the server.
  4. Dirlisting – showing the contents of the directory when a client requests a directory.
  5. FastCGI – for FastCGI proxy support. It acts as a proxy for Fastcgi application servers.
  6. Liana – provides the network layer support to the server.
  7. Logger – the log writer plugin that allows the server to keep track of frequently occurring issues and keep statistics.
  8. Mandril – security plugin that allows to filter incoming requests on the basis of URI or IP addresses.
  9. Polarssl – provides HTTPS support for the server
  10. Proxy reverse – provides support to the server for reverse proxying and routing back requests to backend servers.

Setting up and installation :

Follow the below steps to install and monkey from source code.

git clone https://github.com/monkey/monkey.git 
cd monkey
./configure
make
bin/monkey

Take localhost:2001 in your browser and lo ! You have successfully installed and run monkey server.

monkey_welcome

References :

You could read more about this server here :

  1. http://monkey-project.com/gsoc2014/getting_started
  2. http://edsiper.linuxchile.cl/blog/category/monkey/
  3. Image found here