473,796 Members | 2,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1865
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 "unpickleab le" 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
16694
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 (root@Pentium.suse.de) (gcc version 3.3 20030226 (prerelease) (SuSE Linux)) #1 Wed Aug 6 18:26:21 UTC 2003 Apache 1.3.27-41 PHP 4.3.1-52 MySQL 3.23.55-20
5
298
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 don't have a web app ? --- Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
2
2723
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 in the Cache. When I try and get the object after it's sliding expiration time I get null (as excepted of course), But the problem is that the memory is never cleaned - my application's memory just keeps on growing event after the object...
5
7859
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), after some investgation i found out that most of it being consumed by filesystem caching... thanks to Liam and Phil Sherman for their valuable suggestions. Is it safe to turn off filesystem caching on every tablespaceon the server(i.e. DIO) ??...
2
6141
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 simply be a result of being out of memory.) We're running on IIS 5.1 on a single Windows 2000 server. We have a separate database server - SQL Server 2000 64 bit. Session state is stored on the database.
13
3524
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 chunks it reads, as the memory usage grows to several hundreds MBs according to the Windows task manager before it dies with a MemoryError. I'm positive that these chunks are not referenced anywhere else; in fact if I change the mmap object to a...
28
3454
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 is too good. When I revisit the page or refresh the page, and then redo the script insertion, the browser doesn't even hit the server to check for a newer version of the JavaScript file. The same old script runs with each insertion.
3
1977
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 calls per page OR 500 SQL calls per second). Most of the data doesn't change more than once ever 10 minutes. Basically they are data islands with specific content. We have already implemented a singleton that manages a connection pool. This...
0
14803
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 browser is caching the files he formerly requested from the web server. But if the file is to be loaded a second time, still a request is sent to the web server which then usually is answering with a "304 Not modified" as can be seen in his access...
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.