High performance web apps with C++

  Brainfuckrz        2012-01-08 10:06:48       2,607        0    

It is Christmas over here, and it is time of giving. So I decided to give something back to the community. I guess this is as old as web programming itself. Trying to create C++ web framework. If you search on the web, you can find dozen of guys that had exactly the same idea. I am not different.

For one of the previous projects(discontinued now) I created simple web framework in C++. If you like to hack in C++, here it is. Code is provided as-is, as part of larger application. You can extract framework code itself, use only some portions of it, or use whole application, if you like. I do not offer any kind of support, so do not call me and do not find me liable for any damage or harm produced to you... But if you get rich and I find out that you were using my code, of course, I am gonna sue you :)

Idea with this framework is simple. All code, (including views) is compiled to one shared library(dll in windows parlance). Meaning whole application is contained within one .so file that is loaded to the Apache at the runtime. There is small glue layer, on top of the application itself, that acts as Apache module and calls code inside your module. Views itself, containing embedded c++, are precompiled to c++ source code, and finally included and compiled to final binary .so file. This used to work perfectly for me, but I found performance not to compensate for lack of flexibility of solutions like Rails(think that you have to compile whole code base, everytime you make some change). Here is the example of code in action: 

#pragma once

#include < fenix.h >
#include "log/view.h"
#include "log/click.h"
#include "log/event.h"
#include "model/db_conf.h"

using namespace fenix::web::toolkit;

namespace LogController
{
  FENIX_CONTROLLER(lg)
  {
    string site_id;
    string event_type;

    if( request.isRead() && get_param(request["_id"], site_id) && get_param(request["_e"], event_type))
    {
      tables::Site::obj site = Site::get(get_database(request, "fenix"));
     
     //ID is 24 chars long
    if(site_id.size() == 24 && site->exists(Query().add_cond("_id", site_id)))
    {
      if(event_type == "hit")
      {
        long last_view; //seconds ago
        get_param(request["_tm"], last_view);
        {
          LogRequest log_request(site_id, event_type;
          log_request.load(request);
          ScopedMiddleware mid;
          log_page_view(log_request, last_view, request._timestamp, mid); mid.done();
        }
        return render_< TrackingPixel >();
      }
      /* if(event_type == "cl") { log_click(); } if(event_type == "ev") { log_event(); }*/
    }
  }
   
  return render_< BadRequestResponse >();
  }
}

Or, for example, have a look at the router code here.

Source repo: https://bitbucket.org/dushan01/fenix

Source : http://www.brainfuck.rs/2012-01-07-high-performance-web-apps-with-c-.html

C++  WEB APPS  WEB FRAMEWORK 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

How to get 12 years experience from a 6 year project

Recently IBM has posted an job ad which requires the candidate t have 12+ years experience of Kubernets. The interesting part is that the famous Kubernetes project was first appeared on Github in 2014 only. How can a candidate can have more than 12 years experience on it? Maybe take one day 8 workin