limit Python CGI's frequency of calls to an external database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mab43
    New Member
    • Dec 2009
    • 7

    limit Python CGI's frequency of calls to an external database?

    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 (these would be limited by my host's TOS though..)? I'm very new to these topics but these are ideas I've heard. Thanks.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    I've never really done this kind of thing before.

    But why do you need to update the buffer when no-one's viewing it?

    If you didn't have to, then you just include a time stamp in the buffered data, and then when the user makes a call you check if you're within 10 seconds of that time stamp. If so, you return the buffered data, if not, you update the buffer, and return the new data.

    If you need the buffer to be updated regardless (in which case your user's call would just involve getting whatever the latest data is), then you probably need to look at a background thread.

    But I'm afraid this might be the blind leading the blind here...

    Please let us know how you're getting on.

    Comment

    • mab43
      New Member
      • Dec 2009
      • 7

      #3
      Glenton, thanks, you're right; there's certainly no need to update the buffer when there are no viewers.

      Are there concurrency issues if multiple users are trying to read/edit a buffer file simultaneously? User number would be low and the file size would also be quite low, so maybe not?

      Comment

      • mab43
        New Member
        • Dec 2009
        • 7

        #4
        I ultimately did as Glenton suggested: had the CGI script check to see if ten seconds had elapsed since the last data file-write, if not, get new GPS data and update the data file with a timestamp.

        My code is posted as part of a bus-tracking project here.

        Comment

        Working...