You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Aron Szabo <ar...@gmail.com> on 2007/02/11 13:46:11 UTC

Apache2 Shared Memory problem

Hello!

I`m wrtiting a vhost module for apache2.
I need an array or a hash or an apache table to be WRITABLE/READABLE
from every apache child.
This vhost module is a modified version of vhost-mysql . But I dont
want to do an sql query on every request so i want to cache it after
the request in an apache table (vhost; path) or a hash or something.

Any help is appreciated!

Thanks!

Yours,
Aron

Re: Apache2 Shared Memory problem

Posted by Issac Goldstand <ma...@beamartyr.net>.

Nick Kew wrote:
> On Sun, 11 Feb 2007 13:46:11 +0100
> "Aron Szabo" <ar...@gmail.com> wrote:
> 
>> I need an array or a hash or an apache table to be WRITABLE/READABLE
>> from every apache child.
>> This vhost module is a modified version of vhost-mysql . But I dont
>> want to do an sql query on every request so i want to cache it after
>> the request in an apache table (vhost; path) or a hash or something.
> 
>>>From that description (which you didn't give on IRC), you're probably
> better off forgetting about shared memory, and using a per-process
> cache (with any permanent changes going to the database, of course).

[snip]
>  I already mentioned the easier alternatives
> on IRC.

I'm currently looking into storing some information f(or a completely
unrelated module) on a per-child (per-process) basis (non-persistent
beyond the life of the child).  If this was one of the alternatives
mentioned "on IRC", would you mind re-posting to the list for reference
(actually, even if it's not, would you mind briefly repeating whatever
was discussed)?

Thanks,
  Issac

Re: Apache2 Shared Memory problem

Posted by Aron Szabo <ar...@gmail.com>.
Hello!

static int module_translate_name(request_rec * r) {
	module_config *s_cfg = ap_get_module_config(r->server->module_config,
&fp_module);
	apr_datum_t db_domain_t;
	apr_datum_t db_path_t;

	apr_dbm_open_ex(&s_cfg->file,"DB","/tmp/vhosts.db",APR_DBM_RWCREATE,666,r->pool);

	db_domain_t.dptr = r->hostname;
	db_domain_t.dsize = strlen(r->hostname);
	apr_dbm_fetch(s_cfg->file, db_domain_t,&db_path_t);


	ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, r->server, "DB! %s PID:
%ld",db_path_t.dptr,(long int)getpid());

	if(db_path_t.dptr) {
		r->filename = apr_pstrcat(r->pool, db_path_t.dptr, r->uri, NULL);
	} else {
                                     apr_dbm_close(s_cfg->file);
		return DECLINED;
	}
                   apr_dbm_close(s_cfg->file);
	return OK;
}

Now my problem is that opening the berkeley db file fails when i want
to translate this.

If i open the database per child then it works ok but if i have a
structure like this:

www.1234.com => /var/www

if i access the url after apache restart it works the child fetches
the data from the database. But if i change the database with an
external program than the child does not fetch the data from the
database again and uses the old data.

is there a way to do this ?

Yours,
Aron


On 2/11/07, Nick Kew <ni...@webthing.com> wrote:
> On Sun, 11 Feb 2007 15:23:52 +0000
> Nick Kew <ni...@webthing.com> wrote:
>
> > On Sun, 11 Feb 2007 15:51:37 +0100
> > Michael Wallner <mi...@iworks.at> wrote:
> >
> > > Looking at apr/memory/unix/apr_pools.c, APRs allocator is anything
> > > but a generic infrastructure for implementing my own allocator.
> >
> > If it was, then I daresay memory pools
>
> ... should've read "shared memory pools", of course!
>
>
> --
> Nick Kew
>
> Application Development with Apache - the Apache Modules Book
> http://www.apachetutor.org/
>

Re: Apache2 Shared Memory problem

Posted by Nick Kew <ni...@webthing.com>.
On Sun, 11 Feb 2007 15:23:52 +0000
Nick Kew <ni...@webthing.com> wrote:

> On Sun, 11 Feb 2007 15:51:37 +0100
> Michael Wallner <mi...@iworks.at> wrote:
> 
> > Looking at apr/memory/unix/apr_pools.c, APRs allocator is anything
> > but a generic infrastructure for implementing my own allocator.
> 
> If it was, then I daresay memory pools

... should've read "shared memory pools", of course!


-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

Re: Apache2 Shared Memory problem

Posted by Nick Kew <ni...@webthing.com>.
On Sun, 11 Feb 2007 15:51:37 +0100
Michael Wallner <mi...@iworks.at> wrote:

> Looking at apr/memory/unix/apr_pools.c, APRs allocator is anything
> but a generic infrastructure for implementing my own allocator.

If it was, then I daresay memory pools would be a solved problem.
Maybe even an APR module in its own right.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

Re: Apache2 Shared Memory problem

Posted by Michael Wallner <mi...@iworks.at>.
Nick Kew wrote:
> On Sun, 11 Feb 2007 13:46:11 +0100
> "Aron Szabo" <ar...@gmail.com> wrote:

>> I need an array or a hash or an apache table to be WRITABLE/READABLE
>> from every apache child.
>> This vhost module is a modified version of vhost-mysql . But I dont
>> want to do an sql query on every request so i want to cache it after
>> the request in an apache table (vhost; path) or a hash or something.
> 
> From that description (which you didn't give on IRC), you're probably
> better off forgetting about shared memory, and using a per-process
> cache (with any permanent changes going to the database, of course).
> 
> From what you said on IRC, you've already tried apr_shm.
> That's no use for pointers when dereferencing them takes you
> out of shared memory.  You could add apr_rmm to give you
> pointers, but that still doesn't give you the higher-level
> structs (like array or hash).  For that you'd need a shared
> memory pool, which you might get by implementing a new
> apr_allocator on top of apr_shm/apr_rmm.

Looking at apr/memory/unix/apr_pools.c, APRs allocator is anything
but a generic infrastructure for implementing my own allocator.

Please tell me, if I'm completely off, as I'm interested in this
topic as well!

Regards,
-- 
Michael


Re: Apache2 Shared Memory problem

Posted by Aron Szabo <ar...@gmail.com>.
Hmm ... yes the shm way is too complicated for me :/
I will use apr_dbm (which you already mentioned)

"(10:35:51 AM) niq: use apr_dbm or apr_memcache"

Thanks again!

Yours,
Aron


On 2/11/07, Nick Kew <ni...@webthing.com> wrote:
> On Sun, 11 Feb 2007 13:46:11 +0100
> "Aron Szabo" <ar...@gmail.com> wrote:
>
> > Hello!
> >
> > I`m wrtiting a vhost module for apache2.
>
> This should really be on the modules list.
>
> > I need an array or a hash or an apache table to be WRITABLE/READABLE
> > from every apache child.
> > This vhost module is a modified version of vhost-mysql . But I dont
> > want to do an sql query on every request so i want to cache it after
> > the request in an apache table (vhost; path) or a hash or something.
>
> From that description (which you didn't give on IRC), you're probably
> better off forgetting about shared memory, and using a per-process
> cache (with any permanent changes going to the database, of course).
>
> From what you said on IRC, you've already tried apr_shm.
> That's no use for pointers when dereferencing them takes you
> out of shared memory.  You could add apr_rmm to give you
> pointers, but that still doesn't give you the higher-level
> structs (like array or hash).  For that you'd need a shared
> memory pool, which you might get by implementing a new
> apr_allocator on top of apr_shm/apr_rmm.
>
> If that was an attractive option, I expect someone would have
> done it already.  I already mentioned the easier alternatives
> on IRC.
>
>
> --
> Nick Kew
>
> Application Development with Apache - the Apache Modules Book
> http://www.apachetutor.org/
>

Re: Apache2 Shared Memory problem

Posted by Nick Kew <ni...@webthing.com>.
On Sun, 11 Feb 2007 13:46:11 +0100
"Aron Szabo" <ar...@gmail.com> wrote:

> Hello!
> 
> I`m wrtiting a vhost module for apache2.

This should really be on the modules list.

> I need an array or a hash or an apache table to be WRITABLE/READABLE
> from every apache child.
> This vhost module is a modified version of vhost-mysql . But I dont
> want to do an sql query on every request so i want to cache it after
> the request in an apache table (vhost; path) or a hash or something.

From that description (which you didn't give on IRC), you're probably
better off forgetting about shared memory, and using a per-process
cache (with any permanent changes going to the database, of course).

From what you said on IRC, you've already tried apr_shm.
That's no use for pointers when dereferencing them takes you
out of shared memory.  You could add apr_rmm to give you
pointers, but that still doesn't give you the higher-level
structs (like array or hash).  For that you'd need a shared
memory pool, which you might get by implementing a new
apr_allocator on top of apr_shm/apr_rmm.

If that was an attractive option, I expect someone would have
done it already.  I already mentioned the easier alternatives
on IRC.


-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/