Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Maintaining State efficiently for large numbers of statecodes

by Angel (Friar)
on Sep 08, 2003 at 13:47 UTC ( [id://289770]=perlquestion: print w/replies, xml ) Need Help??

Angel has asked for the wisdom of the Perl Monks concerning the following question:

I am asking this as a hypothetical with some serious applications and I hope that this may help someone else in the future.

I wrote a data entry web application with states in it. I was not aware of CGI::Application or any of the state modules so it took in data and time issued and generated a key made of an MD5 and a random component that allowed me to get the data back out when the page came back. This was stored in a MySQL database.

FUNCTION MAKE_STATECODE

ARGUMENTS:

UserID What state the should go to when this page is recieved Some additional data if needed When the code was issued When it expires ( because some things have a longer timeout )

RETURNS:

A code of speccified length that refers to the data stored in a table allowing the end user to only get the information and pages pertaining to him or her.

This worked really well when I was generating at most five or six codes per page. And we used it for two years. But I worked out a script that masks SQL tables or views and can auto generate tables and forms. I did see some of them in cpan but I did not like the API. Anyway I was generating one statecode for each record to link to each editable record page.

I banged it up so serverely trying to get it to work. That I dont want to show the really ugly code but i will explain the algorithm.

Step One ( to speed things up ) run by cron once a night Open database Loop based on previous days load ( about 10k linkcodes ) Make random statecode with no data. End Loop Step Two ( when i generate a page with linkcodes ) Open Database Try to get statecode not in use If avaliable write data to statecode return statecode Else make new statecodes ( about 100 ) write data to statecode return statecode End If

Then things started to slow way down when I needed a bunch of statecodes ( 1000+ ). I pre-compiled the statement by moving the prepare out of the loop and that helped but not enougth. Multiple inserts did not help much either since the problem is the speed of which data is exchanged between my server and my database server. We are talking about 10 linkcodes a second.

Thus I need a new state module to wrap my existing module around so that the rest of the program is unaware. ( OO rocks! ) what do you reccomend. My disk space is mapped so having it running on several servers at the same time is not an issue.

What I am concerned with is when I pull the data out when the statecode comes back if I do use a flat text file when I have two big tables in use ( which is only for admin view ) thats 4 K linkcodes plus the users and every retrieve is doing a linear search.

Any ideas since using CGI::Session is just going to put me in the same situation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://289770]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found