Jump to content

Server resources cost


rusjoan
 Share

Recommended Posts

What is more "expensive" — simple query to DB or simple check file existence on file system (let's suggest that we work with SSD)?

This question was originated to me recently when I decided to make "Cancel" function in file downloading script.

This script works as background for limited time. It compares current execution time with limitation and breaks download task if time has expired. Also breaking mean removing of all downloaded files, and then task status equals "Fail". "Cancel" function works the same — clear task dir when download has canceled. So execution time check function doesn't require access to hdd or db and we can check it on each file download iteration. Also script makes query to DB to update task download status (percents) no more than once a second (controlled by a separate function).

When I decided to make "cancel download task" function I stuck on a question — what is more optimal to make script check his status for "cancel"? Check for file existence (e.g. "cancel-{taskID}.txt") or check the same in DB?

This all goes from that I'm using PW engine and I can't combine SQL-queries (update task status, check task cancel status..) by engine's native tools. If you work only with engine selectors and don't write any "clear" SQL-queries in a whole project it's obvious to try continue the same :)

UPD: I know that access DB is cheaper than access HDD. But what about SSD?

Link to comment
Share on other sites

I think there is no general answer possible :)

It very much depends on your configuration of MySQL, assuming you're not using another database.

If the query is simple and you have indexes or query for the primary key, it will probably be very fast ;)

Maybe you can do some performance testing for both possibilities?

Cheers

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...