[英]php reading a file and reading data from mysql which one is faster
It's a real php interview question. 这是一个真正的PHP面试问题。 I know the answer is not just which one is faster.
我知道答案不仅仅是哪一个更快。 We can answer it in many aspects.
我们可以在很多方面回答这个问题。 Can anyone give me some suggestions please?
请问有人能给我一些建议吗?
files: 文件:
Database: 数据库:
This is an example of an interview question with no correct answer. 这是一个没有正确答案的面试问题的例子。 A case could be made for either of these things.
可以针对这些事情中的任何一个做出案例。
For files you might say they're quick to load, that there's a lot of kernel optimization around fetching them from disk and providing them to a user process, and even more around sending them directly from disk to a socket via something like sendfile
. 对于文件,您可能会说它们可以快速加载,有很多内核优化可以从磁盘中获取它们并将它们提供给用户进程,甚至可以通过
sendfile
等方式将它们直接从磁盘发送到套接字。 That would be true. 那是真的。
Then for databases you could say that frequently accessed data is stored in memory so there's no I/O round-trip to disk, that could be faster, especially if you're comparing reading parts of a file using a suboptimal structure versus records in a database. 然后对于数据库,你可以说频繁访问的数据存储在内存中,因此没有I / O往返磁盘,这可能会更快,特别是如果你使用次优结构比较文件中的记录而不是数据库。 This is an algorithmic concern as well.
这也是一个算法问题。
So it really depends on what kinds of files and what sort of read/write access patterns are involved. 所以它实际上取决于涉及哪种类型的文件和哪种读/写访问模式。 To say either of these things is faster is to miss the point of the question.
要说这些事情中的任何一个更快就是错过了问题的重点。
Reading one file = fast. 读一个文件=快。
Reading many / big files = slow. 读多个/大文件=慢。
Reading singular small entries from database = waste of I/O. 从数据库中读取单个小条目=浪费I / O.
Combining many entries within the database = faster than file accesses. 组合数据库中的许多条目=比文件访问更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.