General advice - novalexei/mod_servlet GitHub Wiki

General Advice

Let me give you some advice which might save you some time, and maybe even will let you avoid some unnecessary crushes.

  1. Avoid name clashes. When you have multiple web application make sure they don't have classes or factory methods with the same name. mod_servlet loads symbols from shared libraries into the common space. With classes it is easy to avoid with namespaces, but factory methods are declared as extern "C" hence they don't have any namespace. Be careful.

  2. Complex web applications will require various dependencies. There are two ways to hadle dependencies so that they could be found in run time:

  3. One way would be to use an environment variable (like LD_LIBRARY_PATH on UNIX systems) or to copy the dependency library in a library directory where it can be found by the running application (like lib under Apache2 httpd server root);

  4. You also can compile your web application with '-Wl,-rpath=$ORIGIN' flag as I recommended in the beginning of the tutorial and to put dependency libraries to the lib of your web application directory.

The second way seems to be cleaner, because it will contain the whole application including dependencies inside of deployed webapp directory. But sometimes it makes sence to keep some commonly used libraries (like XML or JSON parsers, database libraries, etc) in the place accessible from all webapps.

  1. Use logging always. It is easy to use and log files are invaluable source of information when the application misfunctions.

  2. Configure Apache2 httpd server to use only one child process with multiple threads. This way there will be no need to synchronize data between processes, which is very complex thing to do. Currently, mod_servlet doesn't support session objects shared between processes. If you still want to use multiple processes setup, make sure that you either don't use sessions, or you have your own interprocess synchronized implementation for sessions (you still can use sessionID which you get from http_session, because they are based on cookies and delivered in every request). But the sessions are not the only objects which require interprocess synchronization. All types of caches, mutable static or global variables, etc need it too. Does it really worth it?

  3. Use SSL with dynamic content. Apache2 httpd server supports SSL with mod_ssl. It performs very well. No dynamic application which requires any king of authentication should be deployed without SSL. Also your servlets and filters have access to a lot of SSL related information.

  4. A lot of methods in mod_servlet API return proposed for C++17 string_view. It is important to remember that these are just views to strings with a lifetime of a request. So if you want to cache them - copy to std::string or other appropriate container first.

Looks like this is it. Want to try servlets for your own web application? Good luck, but don't forget to share with me your experience with mod_servlet.

To The Programming Guide