Previously, I was working on a mall website. one module was to customize the homepage, so I could extract the html content of the page and use php to write it into the file. when I read the homepage, I read the file and output it to the template. Reading the database of a question refers to reading custom data, not html content. I am not in a hurry now. I want to know... previously, I was working on a mall website. one module was to customize the homepage, so I could extract the html content of the page and use php to write it into the file. when I read the homepage, I read the file and output it to the template. Reading the database of a question refers to reading custom data, not html content.
I am not in a hurry. I want to know:
If multiple users have high access concurrency, is reading files faster? Or is it faster to read data from the database?
If many files are written, is the reading time slow when the files are large?
The TP framework I used is directly in the template. Will it be better?
How can I test the concurrency? What keywords are to be searched?
Ps: I just got out of work. please give me some advice.
Reply content:
Previously, I was working on a mall website. one module was to customize the homepage, so I could extract the html content of the page and use php to write it into the file. when I read the homepage, I read the file and output it to the template. Reading the database of a question refers to reading custom data, not html content.
I am not in a hurry. I want to know:
If multiple users have high access concurrency, is reading files faster? Or is it faster to read data from the database?
If many files are written, is the reading time slow when the files are large?
The TP framework I used is directly in the template. Will it be better?
How can I test the concurrency? What keywords are to be searched?
Ps: I just got out of work. please give me some advice.
Database data also exists in files, without considering the memory cache of the database, reading files alone is certainly faster than reading the database, because the database must go through the query process and other processing procedures. However, if there are too many files, you also need to consider the file system query speed. this speed is slower than the database query speed when there are too many files.
The file read time depends on the file size, but if all the content in the file is what you want, this time is naturally indispensable. If you only want to read part of the file content, you can use seek to move the file pointer.
The template of the TP framework is compiled. that is to say, in actual execution, the template file you wrote is not used, but the compiled template is used, so you can safely use include, do not worry about performance issues.
Concurrency testing should be called stress testing. you can simply search for a stress testing solution.
For your problem,
In the case of high concurrency, direct databases will certainly be slow. at least there is a Cache layer on the database, and the Cache layer efficiency:
File <Memory (memcache, redis) <Cache array file is also a type of Cache
It seems that you still need to generate static files. Here are some of your keywords:
ob_start
Pseudo-static
CDN
If many files are written, there is no way to do this. we generally use Cache and so on to do the overall architecture scheme, rather than simply writing this simple.
If the read File (especially the php file) is large, enable OpCache to increase the speed.
You include a template file, that is, executed by PHP.include
, Equivalent to PHPinclude
.
If all the static files on the Accessed page need to be embedded into the sub-template, SSI (Apache
,nginX
) Will be better than PHP'sinclude
Faster
Therefore, the answer to your question is: HTML is the fastest, and PHP is not required, but must be generated in advance.
Concurrency testing, from keywordsapache benchmark
First, you will find a lot of content you want.
First, they have little difference in speed, and files are faster, but if they are all stored in the database, it is better to manage them.
Second, who is the most important? These CMS-type websites can be optimized through static. after static, the page generation time is irrelevant.
First, memory> File
Second, the database also stores data in files (of course, the database has a query cache)
Non-relational data, of course, saves files fast
However, a large number of files cannot be stored in the same folder (addressing is slow). you can use the file name directory to separate the files, for example:
File name: dsaferdfsasxfsfsdf. dat
Take the first two characters to create a level-1 directory and store it
Ds/dsaferdfsasxfsfsdf. dat
Lokljljoiomlkml. dat> lo/lokljljoiomlkml. dat
The simple cache method S () provided by TP is the file driver by default. if Memcahced or Redis is used as the cache driver, it is faster than the file, provided that Memached or Redis server is on the local machine, or in a local area network over 1 gigabit
For concurrent testing, the Linux and Darwin (OS x) kernel systems can use the AB command, such:
AB-k-n 1000-c 100 "http://www.baidu.com"
// Initiate 1000 requests with a concurrency of 100 each time (this value has an upper limit. the default value is 256 depending on the system settings)