I had a look at the code in HTTPServerConnection .cpp (version 1.3.6p2), line 86, and the code is making a call to createRequestHandler on the HTTPRequestHandlerFactory object. This returns a new request handler on the heap each time and assigns it to an auto_ptr for eventual cleanup .
- Code: Select all
I have hacked the code a bit so that the handler returned is not deleted, and in my HTTPRequestHandlerFactory implementation, I return the address of the same HTTPRequestHandler each time (which is allocated on the stack). This I did because I thought that allocating a new request handler for each call might be expensive for heavy loads. I tested my code and it works ok. Obviously, the code in the request handler has to be thread and reentrant safe.
Humbly, could I ask as to why this was implemented this way? Why is a new request handler created on the heap for each call? Would the approach I mentioned above make for better performance?
Or maybe, the HTTPServerConnection class could have some kind of option specified - say in the constructor - to denote if request handlers returned by the createRequestHandler call on the factory to be deleted or not? Because in that way, one could implement either approach.
Comments would be appreciated.