这是一个简单的问题。在我们的网站上有一些查询需要花费太多秒才能完成(例如15秒!)。对于匿名流量,他们会获得一个缓存的.html文件,但对于登录用户来说,它太慢了。
查询如下所示:
SELECT node.nid, votingapi_cache_vote_percent_average.value AS votingapi_cache_vote_percent_average_value, votingapi_cache_vote_percent_count.value AS votingapi_cache_vote_percent_count_value, node.type AS node_type, users.name AS users_name, users.uid AS users_uid, node_data_field_species.field_species_nid AS node_data_field_species_field_species_nid, node.title AS node_title, node.changed AS node_changed, node.created AS node_created, node_data_field_picture.field_picture_fid AS node_data_field_picture_field_picture_fid, node_data_field_picture.field_picture_title AS node_data_field_picture_field_picture_title, node_data_field_picture.field_picture_alt AS node_data_field_picture_field_picture_alt, node_data_field_recorded.field_recorded_value AS node_data_field_recorded_field_recorded_value, node_data_field_static_location.field_static_location_value AS node_data_field_static_location_field_static_location_value, field_video_op_videos.video_id AS field_video_op_videos_preview_image_link FROM node node LEFT JOIN votingapi_cache votingapi_cache_vote_percent_average ON node.nid = votingapi_cache_vote_percent_average.content_id AND votingapi_cache_vote_percent_average.content_type = 'node' AND votingapi_cache_vote_percent_average.value_type = 'percent' AND votingapi_cache_vote_percent_average.tag = 'vote' AND votingapi_cache_vote_percent_average.function = 'average' LEFT JOIN votingapi_cache votingapi_cache_vote_percent_count ON node.nid = votingapi_cache_vote_percent_count.content_id AND votingapi_cache_vote_percent_count.content_type = 'node' AND votingapi_cache_vote_percent_count.value_type = 'percent' AND votingapi_cache_vote_percent_count.tag = 'vote' AND votingapi_cache_vote_percent_count.function = 'count' INNER JOIN users users ON node.uid = users.uid LEFT JOIN content_field_species node_data_field_species ON node.vid = node_data_field_species.vid LEFT JOIN content_type_picture node_data_field_picture ON node.vid = node_data_field_picture.vid LEFT JOIN content_field_recorded node_data_field_recorded ON node.vid = node_data_field_recorded.vid LEFT JOIN content_field_static_location node_data_field_static_location ON node.vid = node_data_field_static_location.vid LEFT JOIN content_type_video node_data_field_video ON node.vid = node_data_field_video.vid LEFT JOIN op_videos field_video_op_videos ON node_data_field_video.field_video_video_id = field_video_op_videos.video_id WHERE (node.type IN ('audio','picture','video')) AND (node.status = '1') ORDER BY votingapi_cache_vote_percent_average_value DESC, votingapi_cache_vote_percent_count_value DESC LIMIT 0, 30
memcache会帮助更快地提供该页面吗?或者,至少,第二次访问它......
由于
答案 0 :(得分:2)
昂贵的查询应该以这种或那种方式进行。您发布的查询不依赖于用户登录,因此应缓存。
你是否尝试在管理员中启用激进的缓存,这可能会有所帮助(但可能会在其他地方伤害你)。
如果正在从块运行查询,请确保打开块缓存并且适合查询(这将是BLOCK_CACHE_GLOBAL)。
最糟糕的情况是,您应该考虑为夹点建立自己的缓存。仅作为最后的决定。
update :我猜你正在使用视图来生成页面。我看了here,看起来最新的views2和views3内置了一些缓存,如果你升级就可以使用它。
答案 1 :(得分:1)
使用memcached缓存此查询的输出或由此产生的生成的HTML,确实会在缓存初始结果后加快页面加载。
在此之前,您应该查看视图本身的缓存设置。根据我的经验,这些设置会覆盖设置中的网站范围缓存设置 - >性能。假设您使用的是Drupal 6和Views 2,您可以通过编辑视图,然后单击Basic Settings - >来设置视图的缓存生存期。高速缓存中。
答案 2 :(得分:0)
memcached只是一种缓存机制。您的查询仍然需要执行一段时间。
如果要使用它来使事情更顺畅,请不断查询数据库并在后台的memcached中更新结果,并从缓存中提供信息。这样,信息不会超过15秒左右,但很快就会被检索出来。
您可能还想增加MySQL服务器的缓存。 memcached通常不用于缓存单个查询结果...