hi
On Tue, Mar 11, 2014 at 4:35 AM, Savita Seetaraman < [email protected]> wrote: > Hello, > > While going through the source code, I saw that there is a cache for each > thread ( in src/mk_cache.c ). As soon as the thread is created ( in > src/mk_scheduler.c ), the in the header of the cache are allocated space as > well - last modified, content length, keep-alive, etc.. I am not able to > understand what each of these fields is keep track of. Are these fields of > the request that thread is currently handling ? > > What exactly is the need for caching the headers ? > > I would be grateful if anyone who understood this could explain ? I don't > know if I am missing something obvious... Kindly guide me. > > sure, the mk_cache.c file and it calls aims to provide small cache buffers for specific needs. Imagine that a HTTP server receive 1000 requests per second, and for each response that you compose you need to allocate memory and in some cases format some string, e.g: a common HTTP Response looks as follows: --- HTTP/1.1 200 OK Date: Tue, 11 Mar 2014 14:38:07 GMT Server: Monkey/1.5.0 Content-Type: text/html Last-Modified: Thu, 06 Mar 2014 21:26:42 GMT Content-Length: 6794 --- as you can see there are some things that will never change: 1) Date header: if you get 1000 request per second, the Date header will have the same value, so why allocate a buffer and format string every time ?., its better to have a pre-allocated buffer and have a worker updating the date string every one second. 2) Server: the server signature never changes there are many cases where we want to use a pre-allocated buffer on each thread instead of an on-fly memory allocation, mostly for performance. the tip is: check where those allocations are used, check where pthread_getspecific() is used, regards,
_______________________________________________ Monkey mailing list [email protected] http://lists.monkey-project.com/listinfo/monkey
