473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Caching in memory for Apache

Dear All,

I have decided to take the big plunge and drop the Microsoft platform
and use Mod_Python and Apache in it's place.

I've never used Linux before this project so it's a really big learning
curve, but so far it's going well. I've managed to create some simple
pages using the basic of Python.

One of the questions I have is: How do you cache stuff in memory? Say
I've got a bunch of stuff I need to create from a set of database rows.
Obviously, I do not want to consult the database each time I have a
request for my page. Is there anyway in Mod_python for me to store
values inside memory so I can look it up on the next GET request?

Simon.

Mar 24 '06 #1
4 1840
Pickle (http://www.network-theory.co.uk/docs/pytut/tut_58.html) comes
to mind when anyone mentions wanting to save a value, method, object,
etc without writing to storage (file or db). Is it possible for you to
post some code? There may be an alternative algorithm so you can avoid
writing to "memory."

Harlin Seritt

Mar 24 '06 #2
Simon Johnson wrote:

I have decided to take the big plunge and drop the Microsoft platform
and use Mod_Python and Apache in it's place.
Congratulations! ;-)

[...]
One of the questions I have is: How do you cache stuff in memory? Say
I've got a bunch of stuff I need to create from a set of database rows.
Obviously, I do not want to consult the database each time I have a
request for my page. Is there anyway in Mod_python for me to store
values inside memory so I can look it up on the next GET request?


I suppose that you probably need to use sessions in your application in
order to achieve what you're aiming for. If you're not familiar with
the concept of a session in the context of Web applications, sessions
are just things which associate a particular user or client with
persistent information stored on the server: when sending responses
(ie. Web pages) to users/clients, you include a token which those
users/clients then submit back to you with each request; you use these
tokens to look up any information that you've stored for quick
retrieval; the method of transmitting tokens is most often a "cookie"
which is automatically sent back by browsers unless configured
otherwise.

I know that mod_python does support sessions, including in-memory
sessions, as do a number of different frameworks. It should be fairly
convenient to take database rows and store them in a session, and in
most cases the framework (eg. mod_python) will manage the low-level
details (such as the sending of cookies, and so on). Sometimes, there
are restrictions on what the persistent information in sessions can
actually look like: some implementations use things like pickle, and
you can run into "unpickleable" objects; some implementations recommend
that you only store things like strings or text.

Whether sessions are ultimately the "right" answer rests upon a number
of technical considerations, and some people have stated that they
believe them to be generally inappropriate. However, they're probably
the most immediately appropriate thing for you to use in this case.

Paul

Mar 24 '06 #3
On Fri, 2006-03-24 at 06:56 -0800, Simon Johnson wrote:
Dear All,

I have decided to take the big plunge and drop the Microsoft platform
and use Mod_Python and Apache in it's place.

I've never used Linux before this project so it's a really big learning
curve, but so far it's going well. I've managed to create some simple
pages using the basic of Python.

One of the questions I have is: How do you cache stuff in memory? Say
I've got a bunch of stuff I need to create from a set of database rows.
Obviously, I do not want to consult the database each time I have a
Why not hit the database each time? That's what it is there for. What
you are trying to do is called premature optimization.

You are facing a huge learning curve. My recommendation is to build it
first with close adherence to the KISS principal. After its built, take
it for a spin. If it is too slow, then tune it. Think towards
implementation simplicity, not speed. You will probably find that
whatever you build will be fast enough when you are finished.

request for my page. Is there anyway in Mod_python for me to store
values inside memory so I can look it up on the next GET request?


Your database really is the best place for that.

Good luck - Adam DePrince

Mar 25 '06 #4

Simon Johnson wrote:
Dear All,

I have decided to take the big plunge and drop the Microsoft platform
and use Mod_Python and Apache in it's place.

I've never used Linux before this project so it's a really big learning
curve, but so far it's going well. I've managed to create some simple
pages using the basic of Python.

One of the questions I have is: How do you cache stuff in memory? Say
I've got a bunch of stuff I need to create from a set of database rows.
Obviously, I do not want to consult the database each time I have a
request for my page. Is there anyway in Mod_python for me to store
values inside memory so I can look it up on the next GET request?


It all depends a bit on what you want to cache and whether the data is
specific to one users interaction with a page, or whether the data is
able to be used across requests from multiple users. This will dictate
whether you can use a global data cached within modules used to
generate
the page, whether you can use sessions, shared memory or whether you
have no choice but to always go back to the database.

As others have pointed out, don't get trapped in doing premature
optimisation. More often than not what you may think will be a bottle
neck will not and any problems if they even exist will be elsewhere.

In respect of mod_python, it is also vitally important to understand
the
process/interpreter module under which Python runs within the context
of Apache. A starting point for getting information about this is:

http://www.dscpl.com.au/articles/modpython-004.html

If you do decide that sessions may be useful to what you are doing, as
pointed out by others, there can be limitations as to what data can be
stored. For limitations in respect of sessions in mod_python have a
look
at:

http://www.dscpl.com.au/articles/modpython-005.html

Finally, make sure you use the latest version of mod_python available.
Avoid using mod_python 2.7.X or 3.1.X as there are lots of known issues
and problems. Not all problems are solved in 3.2.X version, but good
progress has been made on getting rid of many issues. The main area
which can still cause problems, especially when trying to cache data in
the Apache process, is that of module loading and reloading. For a run
down on issues in that area see:

http://www.dscpl.com.au/articles/modpython-003.html

A lot of work has already been done on solving these issues for 3.3.X
version of mod_python.

BTW, the best place to ask questions about mod_python is the mod_python
mailing list. Thus, get yourself subscribed to it. Details of the
mailing list
are on the mod_python web site.

Graham

Mar 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
5
by: michaeltorus | last post by:
Is the only way to cache data in Memory, such as a Dom Document, to use System.Web.Caching namespace? I can't seem to find anything else, but what if you want to cache something in memory and you...
2
by: sternr | last post by:
Hey, (Sorry if the thread has been posted twice!) I'm using the System.Web.Caching.Cache object in my Win App and basically, it's great! I use a sliding expiration TimeStamp to the object I put...
5
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated),...
2
by: George1776 | last post by:
All, I've recently upgraded our production ASP.NET/C# application from framework 1.1 to 2.0. Since then I've been plagued by out-of-memory errors and problems with the cache object (which may...
13
by: George Sakkis | last post by:
I've been trying to track down a memory leak (which I initially attributed erroneously to numpy) and it turns out to be caused by a memory mapped file. It seems that mmap caches without limit the...
28
by: Peter Michaux | last post by:
Hi, I'm playing with dynamic script insertion to make a request to the server for a JavaScript file to be automatically run when it arrives in the browser. It works but... The page caching...
3
by: Gary W. Smith | last post by:
I had a couple questions about data caching. We have a site that gets a huge amount of traffic to a few specific pages that have a lot of data on them (300k hits/hour during peak, about 6-10 data...
0
docdiesel
by: docdiesel | last post by:
The fastest (and cheapest) transfer of data is that which doesn't have to be done - because the data is already there. Or still there - the caching of files is widely known and practised. Each web...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.