Database Size Vs PHP Processing Speed
Currently within my application I have a setup where upon submission of data, PHP Processes this data using several functions and then places in the database, for example
The quick brown fox jumps over the lazy dog
Becomes an SEO Title of
the-quick-brown-fox-jumps-over-the-lazy-dog
This string is stored in my database under title_seo
, but my question is as follows.
What is more important:
- The size of the database for storing this extra parsed strings
- Or the resources used converting them
Now when I say "the resources used converting them", I mean that if I was to remove the column from the database and then parse the general title every time I output the contents.
Obviously when parsing every time the content get's called each reque开发者_如何学Cst then the PHP usage increase but the database size decreases.
What should I be more worried about ?
Neither of them.
In this case the computational cost is minimal. But storing the seo_title in your table could allow you to change the url
of your article title to whatever you want.
So I would keep the title_seo
in the db
Relatively speaking hard drive space is considered cheaper then processing time. Therefore only having to waste processing time converting the title to the SEO title one time, and storing both of them in the database is the best option.
I don't have much to add to @yes123's answer, but in the end, the whole idea is that you should look if you can store more data in the database to prevent making unwanted calculations, don't take it as a rule, but mostly I favor storing more Db data vs making more calculations.
In your case, the calculations to convert a string into a SEO string look quite simple, so it wouldn't matter, but sometimes, you have a table with a few things like prices, unit quantity, discount and so on..., it's better to calculate the price when adding the rows than having to calculate it everytime you want to display it.
Hope I can help!
This is a question that is often replied by "depending on your own needs". Any software must have a balance between computing power versus memory used.
However, as many people says these days, "disk space is cheap".
So, going back to square one, ask yourself if you're going to have lots of data, and where are you going to store it (your own server, Amazon S3, etc) but I'll go with the "store only once" option.
if your have millions of pages, seo_title in DB - is bad idea. Good one - is have it as cached value text only.
If your have less than 10 millons pages, but more that 1 mln, - db will maybe need have separate table/s for se title
If your have less records, - no difference at all.
PS. Am thinking of corresponding site size <-> visitors number.
精彩评论