简体   繁体   English

非常频繁地拉出很多行 - 我在这里需要memcached吗?

[英]Pulling very large # of rows very often — do I need memcached here?

I have about 10 tables with ~10,000 rows each which need to be pulled very often. 我有大约10个表,每个表约10,000行,需要经常拉动。

For example, list of countries, list of all schools in the world, etc. 例如,国家列表,世界上所有学校的列表等。

PHP can't persist this stuff in memory (to my knowledge) so I would have to query the server for a SELECT * FROM TABLE every time. PHP不能在内存中保存这些东西(据我所知)所以我每次都要查询服务器的SELECT * FROM TABLE。 Should I use memcached here? 我应该在这里使用memcached吗? At first though it's a clear absolutely yes, but at second thought, wouldn't mysql already be caching for me and this would be almost redundant? 起初虽然它绝对是肯定的,但是第二个想法,不会mysql已经为我缓存了,这几乎是多余的吗?

I don't have too much understanding of how mysql caches data (or if it even does cache entire tables). 我对mysql如何缓存数据(或者甚至是否缓存整个表)没有太多了解。

I'd suggest reading up on the MySQL query cache: 我建议阅读MySQL查询缓存:

http://dev.mysql.com/doc/refman/5.6/en/query-cache.html http://dev.mysql.com/doc/refman/5.6/en/query-cache.html

You could use MySQL query cache, but then you are still using DB resources to establish the connection and execute the query. 您可以使用MySQL查询缓存,但之后您仍然使用数据库资源来建立连接并执行查询。 Another option is opcode caching if your pages are relatively static. 如果您的页面相对静态,则另一个选项是操作码缓存 However I think memcached is the most flexible solution. 但是我认为memcached是最灵活的解决方案。 For example if you have a list of countries which need to be accessed from various code-points within your application, you could pull the data from the persistent store (mysql), and store them into memcached. 例如,如果您有一个需要从应用程序中的各个代码点访问的国家/地区列表,您可以从持久存储(mysql)中提取数据,并将它们存储到memcached中。 Then the data is available to any part of your application (including batch processes and cronjobs) for any business requirement. 然后,数据可用于任何业务需求的应用程序的任何部分(包括批处理和cronjobs)。

You do need some kind of a cache here, certainly; 你肯定需要某种缓存,当然; layers of caching within and surrounding the database are considerably less efficient than what memcached can provide. 数据库内部和周围的缓存层的效率远低于memcached可以提供的效率。

That said, if you're jumping to the conclusion that the Right Thing is to cache the query itself, rather than to cache the content you're generating based on the query, I think you're jumping to conclusions -- more analysis is needed. 也就是说,如果你得出的结论是正确的东西是缓存查询本身,而不是根据查询缓存你正在生成的内容,我想你会得出结论 - 更多的分析是需要。

What data, other than the content of these queries, is used during output generation? 在输出生成期间使用除了这些查询的内容之外的哪些数据? Would a page cache or page fragment cache (or caching reverse-proxy in front) make more sense? 页面缓存或页面片段缓存(或前面的缓存反向代理)是否更有意义? Is it really necessary to run these queries "often"? 是否真的有必要“经常”运行这些查询? How frequently does the underlying data change? 底层数据的变化频率如何? Do you have any kind of a notification event when that happens? 发生这种情况时,您是否有任何通知事件?

Also, SELECT * queries without a WHERE clause are a "code smell" (indicating that something probably is being done the Wrong Way), especially if not all of the data pulled is directly displayed to the user. 此外,没有WHERE子句的SELECT *查询是“代码味道”(表示某些事情可能正在以错误的方式完成),特别是如果并非所有数据都被直接显示给用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM