Main  /  Edit  /  History  /   /  Users Area

Event Loop

Event Loop and Thread Pool interaction

The CppCMS service has a simple design of a single event loop, and a thread pool that handles actual user application responses.

Every new incoming FastCGI, SCGI or HTTP request is accepted by the CppCMS service and handled by the fast and efficient CppCMS event loop that is based on epoll, kqueue, /dev/poll or select system calls.

On an incoming request, a special HTTP Context is created. It prepares the incoming request, reads all POST data and if required parses it within the central event loop.

Once the request is ready, it is checked against the CppCMS applications pool to detect which application object handles it.

If the application that handles it is a synchronous application, its execution is passed to the thread pool. The user application prepares the response and sends it synchronously to the client and the context is destroyed, completing the "request/response" cycle.

If the application is asynchronous, the HTTP Context remains inside the event loop's thread and it is handled by the asynchronous application. This application may decide to complete the response immediately or postpone it by implementing, for example, long polling.

Integration with CppCMS Event Loop

There are several ways to interact with the event loop, besides the obvious - implementing your own asynchronous application:

  1. Use the cppcms::service::get_io_service() function to access the event loop directly.

    You can use any of the booster::aio classes there and handle various asynchronous events.

  2. You can post various operations for execution in the event loop using cppcms::service::post() from other threads.

    This is especially important when you want to do integration between synchronous and asynchronous applications.

    You should remember that most of the CppCMS objects including http::context are not thread safe for access from multiple threads, so if some operation should be executed on objects running in the event loop, it must be done by posting handlers for execution in the event loop.

It is important to remember that every operation executed in the event loop should be very fast and never block.


CppCMS 1.x.x Configuration | Top | Understanding Application Lifetime

About

CppCMS is a web development framework for performance demanding applications.

Commercial

CppCMS is available under Open Source and Commercial Licenses.

For more details, visit our website: commercial.cppcms.com

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page



Valid CSS | Valid XHTML 1.0