Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Time reading file size

by htmanning (Friar)
on Jan 16, 2018 at 01:10 UTC ( [id://1207329]=perlquestion: print w/replies, xml ) Need Help??

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

Monks,

I have a site that I have a Settings database for. My scripts check the database for certain preferences for the site. However, adding an additional database call seems to slightly slow down my search script, so my workaround is to write text to a .txt file whenever I change a certain preference. If the preference is set to YES I put the word "yes" in the .txt file. If it's set to NO, I zero out the .txt file. Then, in the search script, I check the file size of the .txt file. If it is zero I do one thing, if it is anything more than zero I do another.

My question is, doesn't this also add additional time to the search script? It seems like I can tell the difference in using the flat file but I wanted some feedback on it. Do you think it is faster to read the file size or make the database call?

I do have a .sub file that gets read by the search script on every load. I could hard code this preference there, but I want to be able to set the preference in a browser. Therefore, I'm using the .txt workaround.

Thanks!

Replies are listed 'Best First'.
Re: Time reading file size
by hippo (Bishop) on Jan 16, 2018 at 09:07 UTC
    Do you think it is faster to read the file size or make the database call?

    That depends entirely on your database and your filesystem and is therefore impossible to tell from this distance. But why guess when you can Benchmark?

Re: Time reading file size
by Anonymous Monk on Jan 16, 2018 at 14:15 UTC
    You are effectively using the filesystem as a database and trusting that the directory-entry correctly reflects the file size. Benchmarking will probably reveal that your approach is slower. Read the preferences from the database once and keep them in memory. Don't retrieve them in a loop.
      Thank you. I'm always leary of too many database calls, but it appears too many Apache calls can be equally, or more taxing. I have no idea how to write to particular part of a .sub file so I did the workaround.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found