Overview
Features
Download
Documentation
Community
Add-Ons & Services

Creating Scalable Web Server

Please post support and help requests here.

Creating Scalable Web Server

Postby varunc_h » 26 Nov 2008, 08:53

Hello,
I need to create a scalable webserver using asynchronous IO which needs to handle a lot of client requests. My requirement is to catch the GET request from clients parse it and send an xml back. For that i have created a sample model by editing the TimeServer example of POCO and tested with Microsoft ACT. The perfomance is good but it cannot handle more than 50 simultaneous browser connections. ACT shows many socket errors. can u pls review my code and guide me what other classes or design methods i must use to improve the scalability of the server.
Code: Select all

class ASEServerConnection: public TCPServerConnection
{
public:
   ASEServerConnection(const StreamSocket& s):
      TCPServerConnection(s)
      {    }
   void run()
   {
      Application& app = Application::instance();
      
      try
      {   
         //Application Logic
         char buff[1024];
         char response[1024] = "HTTP/1.1 200 OK
"
            "Content-Type: text/txt
"
            "Content-Length: 5

"
               "abcde";
         socket().receiveBytes(buff,1024,0);
         socket().sendBytes(response,1024,0);
      }
      catch (Poco::Exception& exc)
      {
         app.logger().log(exc);
      }
   }   };

class ASEServerConnectionFactory: public TCPServerConnectionFactory
   
{
public:
   ASEServerConnectionFactory()      
   {
   }
   
   TCPServerConnection* createConnection(const StreamSocket& socket)
   {
      return new ASEServerConnection(socket);
   }
};

class ASEServer: public Poco::Util::ServerApplication
{
public:
   ASEServer()
   {
   }
   
   ~ASEServer()
   {
   }

protected:
   void initialize(Application& self)
   {
      ServerApplication::initialize(self);
   }
      
   void uninitialize()
   {
      ServerApplication::uninitialize();
   }

   void defineOptions(OptionSet& options)
   {
      ServerApplication::defineOptions(options);
   }

   void handleOption(const std::string& name, const std::string& value)
   {
   }
   
   int main(const std::vector& args)
   {
      // get parameters from configuration file
      unsigned short port = (unsigned short) config().getInt("ASEServer.port", 9911);      
      // set-up a server socket
      ServerSocket svs(port);
      // set-up a TCPServer instance
      TCPServer srv(new ASEServerConnectionFactory(),svs);
      std::cout << srv.maxConcurrentConnections();
      // start the TCPServer
      srv.start();
      // wait for CTRL-C or kill
      waitForTerminationRequest();
      // Stop the TCPServer
      srv.stop();
      
      return Application::EXIT_OK;
   }
};

int main(int argc, char** argv)
{
   ASEServer app;
   return app.run(argc, argv);
}

what i need is the server must handle maximum simultaneous browser connections. I have tested another prototype using IOCompletion Port and Asynchronous IO. Eventhough the perfomance is slow it can handle maximum of upto 500 simultaneous browser connections with zero socket errors. Hope you guys will suggest me a good design.
varunc_h
 
Posts: 2
Joined: 25 Nov 2008, 13:56

Re: Creating Scalable Web Server

Postby karim » 26 Nov 2008, 13:13

Try specifying a thread pool, the default has only 16 thread.

ThreadPool * pPool = new ThreadPool(16,1024);
TCPServer srv(new ASEServerConnectionFactory(),svs,*pPool);


Please see documentation for more info about ThreadPool.



karim
 
Posts: 2
Joined: 12 Jan 2008, 22:23
Location: Morocco

Re: Creating Scalable Web Server

Postby alex » 26 Nov 2008, 14:46

> Hope you guys will suggest me a good design.

This has been [https://sourceforge.net/mailarchive/forum.php?thread_name=4800E259.60300%40mansionfamily.plus.com&forum_name=poco-develop|discussed] before. There was even a [url=http://pocoproject.org/poco/wiki/tiki-index.php?page=PocoAIO|wiki suggestion page] created. In the meantime, we have heard that some folks have tweaked POCO on Linux using /dev/poll. The best approach to this problem in POCO context is probably to wrap http://monkey.org/~provos/libevent/]libevent[/url or similar library.

Anyone willing to contribute is welcome to do so. We'll provide sandbox write permission and you can play there.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Creating Scalable Web Server

Postby varunc_h » 27 Nov 2008, 16:02

Thanks for the help karim. Increasing the threadpool gives me a satisfactory improvement in perfomance ie RPS getting high. But still handling only 50 simultaneous browser connections with zero socket errors.

Thanks :)
Varun C H
varunc_h
 
Posts: 2
Joined: 25 Nov 2008, 13:56

Re: Creating Scalable Web Server

Postby pcunite » 29 Nov 2008, 03:06

^Thanks for the help karim. Increasing the threadpool gives me a satisfactory
improvement in perfomance ie RPS getting high. But still handling only 50
simultaneous browser connections with zero socket errors. ^

Have you tried the C++ Ptypes library? I am wanting to use Poco but this would be major hurdle to using it. Is there a way I could donate money to have this problem solved? I don't code in C++ libraries to run into these kinds of issues.
pcunite
 
Posts: 5
Joined: 18 Nov 2008, 03:07
Location: United_States

Re: Creating Scalable Web Server

Postby pcunite » 29 Nov 2008, 03:45

Interesting reading...
Poco needs a __Leader-Follower __

http://www.orbzone.org/wp-print.php?p=56
pcunite
 
Posts: 5
Joined: 18 Nov 2008, 03:07
Location: United_States

Re: Re: Creating Scalable Web Server

Postby alex » 29 Nov 2008, 16:29

> Is there a way I could donate money to have this problem solved?

Sure, I'll [https://sourceforge.net/services/service_details.php?service_listing_id=2322|code for money] (:biggrin:).

As for the model how to implement scalable server architecture, see [url=http://www.kegel.com/c10k.html|C10K] or http://www.cs.wustl.edu/~schmidt/PDF/proactor.pdf]Proactor pattern[/url.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: Creating Scalable Web Server

Postby alex » 01 Dec 2008, 16:33

> some folks have tweaked POCO on Linux using /dev/poll

Correction: I meant to say __poll()__, not /dev/poll.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron