You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Jérôme Renard <jr...@ez.no> on 2009/05/23 21:07:05 UTC
persistent data : common/best practices
Good evening list,
I am working on a module which interacts with a database by using mod_dbd.
My use case is actually the following :
- I have to fetch a few rows in a specific table (around 10 rows)
but I do not want to fetch these rows for every request as I know
they will not change often (but I can not use a configuration file here).
I thought about "caching" the result of this fetch so it is created once
and every subsequent request could use it without hammering the database.
The problem is that I have no clue on how to do it. I mean I can manage with
the code and APR/APR-utils, but how could I do it right ?
Any hint/comments/ideas are much welcome.
Thanks in advance for any help and have a nice week-end.
Best Regards.
--
Jérôme :)
Re: persistent data : common/best practices
Posted by Jérôme Renard <jr...@ez.no>.
Hi Joe,
joe@joe-lewis.com a écrit :
>> My use case is actually the following :
>>
>> - I have to fetch a few rows in a specific table (around 10 rows)
>> but I do not want to fetch these rows for every request as I know
>> they will not change often (but I can not use a configuration file
>> here).
>>
>> I thought about "caching" the result of this fetch so it is created once
>> and every subsequent request could use it without hammering the database.
>
> My suggestions :
>
> - Populate an apr_table_t with the data.
> - Use a shared memory segment so that if you use the prefork MPM, each
> process can still access the data (use mutexes to keep things sane).
> - Use a time stamp on the data entries just so that (after they
> "expire") you can go back and reload the data from the database.
> - Use a configuration option to set the "expire" value so that the
> module can be adjusted as the load on the db increases.
>
> I don't have any example code with me right now due to where I am, but you
> should be able to google for it, or even check the apache source for
> examples. There is much out there.
Thanks for your help! :)
--
Jérôme :)
Re: persistent data : common/best practices
Posted by jo...@joe-lewis.com.
> My use case is actually the following :
>
> - I have to fetch a few rows in a specific table (around 10 rows)
> but I do not want to fetch these rows for every request as I know
> they will not change often (but I can not use a configuration file
> here).
>
> I thought about "caching" the result of this fetch so it is created once
> and every subsequent request could use it without hammering the database.
My suggestions :
- Populate an apr_table_t with the data.
- Use a shared memory segment so that if you use the prefork MPM, each
process can still access the data (use mutexes to keep things sane).
- Use a time stamp on the data entries just so that (after they
"expire") you can go back and reload the data from the database.
- Use a configuration option to set the "expire" value so that the
module can be adjusted as the load on the db increases.
I don't have any example code with me right now due to where I am, but you
should be able to google for it, or even check the apache source for
examples. There is much out there.
Best wishes!
Joe