After a good example of efficient record handling...
NeilF
created: 2006-01-01 16:18:03

My current forum uses flat text files and reads/writes the entire file when adding a new message.

I'd like to look into using fixed length files for indexes etc for faster and more efficient data handling.

I've searched, googled and even downloaded example forums, but cannot see examples.

Can anyone point me to some example of good record handling - eg using seek etc to only update the records required. If its code specifically for a forum all the better!!!

Edited 1 Jan 2006, by footpad: Added basic formatting tags.

Re: After a good example of efficient record handling...
BUU
created: 2006-01-01 16:20:20
Er, this is an extremely solved problem. Why don't you use one of the fifteen million solutions already in existance?
Re^2: After a good example of efficient record handling...
created: 2006-01-01 16:45:42
Why don't you use one of the fifteen million solutions already in existance?
Why not be helpful and point him to at least one of them since they are indeed so copious?

thor

The only easy day was yesterday

Re^3: After a good example of efficient record handling...
BUU
created: 2006-01-01 21:34:34
Honestly I figured he already knew about them. I mean, who hasn't heard of mysql? Or postgresql, or berkeley database, and so on?
Reaped: Re^4: After a good example of efficient record handling...
created: 2006-01-01 23:15:21
This node was taken out by the NodeReaper on 2006-01-02 00-47-11
Reason: [jdporter]: troll trash

You may view the original node and the consideration vote tally.

Reaped: Re^4: After a good example of efficient record handling...
created: 2006-01-01 23:31:14
This node was taken out by the NodeReaper on 2006-01-02 00-42-10
Reason: [jdporter]: troll trash

You may view the original node and the consideration vote tally.

Re^4: After a good example of efficient record handling...
created: 2006-01-02 01:56:03
Honestly I figured he already knew about them. I mean, who hasn't heard of mysql? Or postgresql, or berkeley database, and so on?
Obviously, he didn't. Or at least he didn't think to apply one of those solutions to his problem. Also, you could have just answered "you may want to try a database solution" instead of being vague. Sometimes, even a little bit of info (and courtesy) go a long way.

thor

The only easy day was yesterday

Re^2: After a good example of efficient record handling...
created: 2006-01-01 18:47:38
Please point me at one or two that I can look at please...
Reaped: Re^2: After a good example of efficient record handling...
created: 2006-01-01 23:18:12
This node was taken out by the NodeReaper on 2006-01-02 00-53-50
Reason: [jdporter]: troll trash

You may view the original node and the consideration vote tally.

Reaped: Re^2: After a good example of efficient record handling...
created: 2006-01-01 23:20:53
This node was taken out by the NodeReaper on 2006-01-02 00-41-51
Reason: [jdporter]: troll trash

You may view the original node and the consideration vote tally.

Re: After a good example of efficient record handling...
created: 2006-01-01 16:49:55

Are you sure you want to use fixed-length record sizes for forum posts? Do you have a small maximum length for the body of the post? If not, all of your records will be the size of the largest possible record -- and if that's not small, you'll have to do a lot of IO to read each message from the disk, pull it through the cache, and get it where perl can handle it. If you really think that will improve your speed (and I don't, even without benchmarking it), you need some sort of unique ID per message which you can use as an offset into the file. Multiply that by the size of a record and use seek and sysread on a filehandle to extract just the record you want.

If that doesn't seem fun to you (and it's not), you could use a unique record separator between records and let CPAN://Tie::File take care of reading and writing.

If this were my project, I would use CPAN://DBD::SQLite and avoid all of the tedious mucking about with O(n) access and let indexed columns get that down to O(log n) or better, while not having to process all of the data myself. Please consider that instead.

Re: After a good example of efficient record handling...
created: 2006-01-01 18:37:49
Taking your performance/io problems in Perl always reads in 4K chunks and writes in 1K chunks... Loads of IO! into account, i think you could use a flat file for storing post titles and a reference to a file that contains the actual post.


holli, /regexed monk/
Re^2: After a good example of efficient record handling...
created: 2006-01-01 18:47:04
I agree, but I can see lots of problems/unkowns with this and would like to see and article or even better a working example...
Reaped: Re: After a good example of efficient record handling...
created: 2006-01-01 23:27:55
This node was taken out by the NodeReaper on 2006-01-02 01-56-18
Reason: [chromatic]: (reap) personal attack

You may view the original node and the consideration vote tally.

Re: After a good example of efficient record handling...
created: 2006-01-02 04:23:50
See pack and unpack for record handling; sysopen, sysseek, sysread, syswrite for retrieving or writing records; and flock for keeping the files from being modified during writes. As mentioned above, post contents should be in a separate file, with the post record containing just start and end offsets. This keeps your records neat and fixed-length. If your users are allowed to do edits, you should allocate a few extra characters for post content so small increases don't require moving it to a new spot in the file. After the time limit for edits is reached, your clean-up utility can rewrite the content to exact size.

It would, however, be simpler to just do this with mySQL. Certain things like indexes can get quite complicated to program.

perlmonks.org content © perlmonks.org and BUU, chromatic, holli, NeilF, NodeReaper, TedPride, thor

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03