473,406 Members | 2,633 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,406 software developers and data experts.

limit Python CGI's frequency of calls to a database?

7
I've got a Python CGI script that pulls data from a GPS service; I'd like this information to be updated on the webpage about once every 10s (the max allowed by the GPS service's TOS). But there could be, say, 100 users viewing the webpage at once, all calling the script.

I think the users' scripts need to grab data from a buffer page that itself only upates once every ten seconds. How can I make this buffer page auto-update if there's no one directly viewing the content (and not accessing the CGI)? Are there better ways to accomplish this? Database? Server-side cron? I'm very new to these topics but these are ideas I've heard.
Dec 16 '09 #1
5 1708
gits
5,390 Expert Mod 4TB
the serverside cron is a good start. let the cron write a file every 10s and then write a script that reads the file. the webpage just calls the 'reader-script' -> so you would have your 'buffer-page' ...

kind regards
Dec 16 '09 #2
mab43
7
gits -- thanks, I read into my host's TOS and they don't want cron jobs running more than once every 15 minutes.. What if I had a local script pull GPS data every 10s then upload a new file to the server if the data has changed? That just seems inefficient but I'm struggling to think of another option.
Dec 16 '09 #3
gits
5,390 Expert Mod 4TB
you could even have a serverside script that reads the gps-data ... and writes a file. when that is done just write a lockfile and then let the next request read from the file. after 10s just remove the lockfile and read again from the GPS-service to write a new file - to give you just another idea ...

kind regards
Dec 19 '09 #4
acoder
16,027 Expert Mod 8TB
Another possibility: use a database to store the results and the time that the results were retrieved in a cache. If the time has elapsed (time retrieved > result retrieve time + 10s), then make a new request. If no users are viewing the page for a length of time, there's no need to make a request every 10 seconds. You just make the next request when the next user views the page by which time 10 seconds will have passed.
Dec 22 '09 #5
mab43
7
acoder, thanks, this is exactly what I did. The script checks the timestamp of the data first thing and only fetches new data if ten seconds have elapsed. The data file is updated after a new fetch. Thanks again; here's the code I used.

I guess my last worry is about read/write interference if the system takes on a lot of users at once. Maybe I'll try gits' write-lock idea...
Dec 26 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Michael Foord | last post by:
I've come across a couple of 'features' in Python standard libraries - and I'm not sure if they're meant to be there... or if they're bugs... One in urllib2 and one in cgi. >>> from urllib2...
11
by: NC Tim | last post by:
Hello, I think the question i have is fairly straightforward, but I can't seem to replicate the old SAS frequency procedure when I try to accomplish this in MS Access. anyway, i have about 10...
4
by: pmcgover | last post by:
I enjoyed Paul Barry's September article in Linux Journal entitled, "Web Reporting with MySQL, CSS and Perl". It provides a simple, elegant way to use HTML to display database content without any...
3
by: mab43 | last post by:
I've got a Python CGI script that pulls data from a GPS service; I'd like this information to be updated on the webpage about once every 10s (the max allowed by the GPS service's TOS). But there...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.