httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jaysingh Samuel <jayasingh.sam...@hotmail.com>
Subject RE: Load memory dyanamically using handler.
Date Fri, 30 Jan 2009 12:47:10 GMT

Hai all, 

Iam loading huge hash map in the shared memory, and the hash map can be reloaded again by
hitting the handler without server restart. I use the apr_shm to create the shared memory
and the apr_rmm to manage the memory.. 

I create around 1 GB of shared memory which i manage. Because of this implementation i find
the apache server to be very slow.. 

I use the worker mpm.. Please guide me how to reduce the apache startup time. 

I guess the shared memory reduces the apache performance when we create huge shared memory.
But when i read some books which shows the shared is the fastest IPC approach. Is that correct?

Is there any method to faster the processing speed with the Shared memory?. 

Please guide me.. 

Thanks in Advance, 
Jaysingh Samuel.



From: jayasingh.samuel@hotmail.com
To: modules-dev@httpd.apache.org
Subject: RE: Load memory dyanamically using handler.
Date: Fri, 12 Dec 2008 18:52:39 +0530








Hai all, 

 

Thanks a lot for your inputs and the mod_shmget source code. 

 

I have tried the apr_shm and apr_rmm api's for shared memory and dynamic allocating space
for member elements and was working fine.. 

 

I did something like this. 

My struture is. 

 

typedef struct {
    char *name; 
}shared_struct_t;


Where the shared_struct_t is a array of 100. and the name member element have to dyanamically
malloced on the code flow. 

 

I found it difficult first only by getting a junk of memory from arr_shmcreate which i was
not able to malloc further for space for the member element. 

 

The rmm (relocated memory management is the apache api which helps to manage any junk of memory).
So i first create a Junk of memory which is shared and then i initialize with the rmm and
further i was able to use this Junk of memory to allocate memory dyanamically to different
elements i want.. 

 

http://apr.apache.org/docs/apr-util/0.9/group__APR__Util__RMM.html


Thanks, 

Jaysingh. 


> Date: Thu, 11 Dec 2008 22:16:42 +0100
> From: sorinm@gmail.com
> To: modules-dev@httpd.apache.org
> Subject: Re: Load memory dyanamically using handler.
> 
> On Thu, Dec 11, 2008 at 22:08, Sorin Manolache <sorinm@gmail.com> wrote:
> > On Thu, Dec 11, 2008 at 19:55, Ray Morris <support@bettercgi.com> wrote:
> >> On 12/10/2008 02:09:19 AM, Sorin Manolache wrote:
> >>
> >>> I would propose the following approach:
> >>>
> >>> Hook post_config. This one is executed once by the parent process
> >>> before any child is spawned. Therefore, any resource opened there is
> >>> inherited by all child processes. Thus, I would create _shared_
> >>> memory
> >>> structures (see apr_shm.h, not malloc).
> >> ...
> >>> Next, in child_init, _attach_ to the shared memory segment (see
> >> ...
> >>> I hope this helps. You can contact me for a code sample
> >>> if you want. I don't have it handy for the moment, but
> >>> I can find it.
> >>
> >> I've seen several variations of this same
> >> question posted, so any sample code you may be
> >> able to locate may be very helpful to a lot of
> >> people. I'm sure I'll need it at some point,
> >> so I'd file it for future use. With your permission
> >> I'd post it somewhere for Google to find when people
> >> want to know about ways of sharing data in Apache.
> >
> > Attached.
> 
> Also, please note that in this example the shared data is trivial
> enough (an integer) to not use protection against shared data
> corruption through concurrent access.
> 
> For more complicated scenarios, where some sort of protection is
> needed, see apr_thread_rwlock.h.
> 
> >>
> >> On 12/10/2008 02:09:19 AM, Sorin Manolache wrote:
> >>> On Wed, Dec 10, 2008 at 06:00, Jayasingh Samuel
> >>> <jayasingh.samuel@hotmail.com> wrote:
> >>> >
> >>> >
> >>> > I have 100's of files stored in different directories and i load
> >>> all
> >>> these in the memory in arrays and hash table. and i want to reload
> >>> the
> >>> memory automatically using some handlers. When i do this in only the
> >>> particular child thread is having the updated one and the other
> >>> request are showing me the old Datas.
> >>> >
> >>> > 1. The shared memory to store all the 100's of files in array and
> >>> hash table which is dynamically malloced and stored will be too
> >>> costly
> >>> also the synchronization.
> >>> > IS there any other way we can overcome this.
> >>> >
> >>> > 2. Is there any way a handler can directly access the parent
> >>> process, updating the memory and removing the child process which has
> >>> the old Data and spawning the new child process. Can we use the
> >>> mod_balancing technique of blocking the request to the server and
> >>> then
> >>> update the parent and kill the child and spawn new childrens with the
> >>> updated memory.
> >>> >
> >>> > Please guide me with you ideas.
> >>>
> >>> Killing processes at each update is not efficient.
> >>>
> >>> I would propose the following approach:
> >>>
> >>> Hook post_config. This one is executed once by the parent process
> >>> before any child is spawned. Therefore, any resource opened there is
> >>> inherited by all child processes. Thus, I would create _shared_
> >>> memory
> >>> structures (see apr_shm.h, not malloc).
> >>>
> >>> Beware, post_config is run every time the server configuration is
> >>> reloaded. Therefore, such shared memory structures would be created
> >>> after each config reload. In order to avoid eating up the system's
> >>> resources, you'll have to make sure that each created structure is
> >>> also destroyed. In order to do this, _register_ a function (see
> >>> apr_pool_register_cleanup) that is called when the conf pool is
> >>> destroyed. This function would destroy the shared memory structures.
> >>>
> >>> Next, in child_init, _attach_ to the shared memory segment (see
> >>> apr_shm.h). From then on, the shared memory structures are shared
> >>> among all child processes. Each change is visible instantly in all
> >>> processes.
> >>>
> >>> Obviously, think of synchronisation. When not every atomic change
> >>> results in a consistent state of the shared data, you'll have to
> >>> protect the shared data with mutexes. See apr_thread_mutex.h and
> >>> apr_thread_rwlock.h and maybe others. Mutexes should be created in
> >>> post_config too.
> >>>
> >>> I hope this helps. You can contact me for a code sample if you want.
> >>> I
> >>> don't have it handy for the moment, but I can find it.
> >>>
> >>> S
> >>>
> >>>
> >>> --
> >>> A: Because it reverses the logical flow of conversation.
> >>> Q: Why is top-posting frowned upon?
> >>> A: Top-posting.
> >>> Q: What is the most annoying thing in e-mail?
> >>>
> >>>
> >>
> >>
> >>
> >
> >
> >
> > --
> > A: Because it reverses the logical flow of conversation.
> > Q: Why is top-posting frowned upon?
> > A: Top-posting.
> > Q: What is the most annoying thing in e-mail?
> >
> 
> 
> 
> -- 
> A: Because it reverses the logical flow of conversation.
> Q: Why is top-posting frowned upon?
> A: Top-posting.
> Q: What is the most annoying thing in e-mail?


Keep up with trends of the thread on MSN Lifestyle. Fashion is no more a passing phase. Check
it out!
_________________________________________________________________
Find a better job. We have plenty. Visit MSN Jobs
http://www.in.msn.com/jobs
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message