Posts Tagged ‘drupal_lookup_path’

drupal performace:kill drupal_lookup_path and reduce a lot select

April 24th, 2010

p:This is a translated post of “http://www.trackself.com/archives/432.html” before i post it to drupal.org.

Because of my poor english  , i will cut the crap.

using this method will reduce my site  form 77 selects  to 43 ,and copy the same method to taxonomy_get_term , will then reduce from 43 to 28 ,  if you’re using pathauto and path and a lot terms , it’s a lot more useful.

1.after using cacherouter and trun on drupal normal cache ,  my site  still have  77 select per view when login.

2.using devel , i found a lot of drupal_lookup_path and taxonomy_get_term

3.learning from http://drupal.org/node/192448 and http://www.lullabot.com/articles/a_beginners_guide_to_caching_data ,  i use  “PHP static “  plus “drupal cache_set” to reduce the selects.

4.locate include/path.inc , found :

$alias = db_result(db_query(.....", $path, $path_language));

change it to

http://www.trackself.com/code/drupal_get_path.txt

you should read the Chinese version here if you want to know clearer.

Share

drupal performance:减少drupal_lookup_path,减少drupal数据库查询

April 24th, 2010

0.如果你不需要path模块和pathauto模块,则千万不要安装他们,按我看,以中文标题为主的站压根没必要用pathauto。另外至drupal 6.13为止,核心模块特别是path是安装后不能非常直接的卸载的(有点技巧),虽然在模块管理页面上显示已经删除成功了。所以如果曾经使用过pathauto模块,必然在打开页面的时候出现一堆的drupal_lookup_path的查询,少则30-40个,多则200个。即便 每个的查询只需要小于1ms的时间,但并发数太大了,会直接影响使用的

2.使用drupal内置cache再加上cacherouter模块能在一定程度减少查询,但不能减少drupal_lookup_path。

hack core的原因:

1.减少drupal_lookup_path除了完全卸载path相关的模块外

2.还可以hack core,很多人不喜欢hack core 甚至drupal.org上也不建议这样做,但是于我来说,drupal只是个工具,我想让工具按我的想法去做,而不是我按工具的设计思路去做,所以我喜欢hack core

3.另外则是,drupal升级一个小版本,至少是两个月的事,甚至越到后面越慢,为什么不hack core呢。

4.hack core只需要几行代码,而要达到同样的不hack core的效果,要GOOGLE半天也不一定有解决办法。

我的站http://feedme.trackself.com使用了cck+views+panels,非注册用户我直接使用静态的,但注册用户登陆后居然每个页面都至少进行73次数据库查询!其中有30个是drupal_lookup_path

下面结束废话,开始我的解决办法:

___________________________________________

1.粗略查看一下这个函数:http://api.drupal.org/api/function/drupal_lookup_path/6

2.GOOGLE一下有没有别人做过类似的事,居然还真有.这里有个hack core 的技巧,在drupal上,hack core都叫patch , 所以:google drupal_lookup_path  patch ,第一个记录就是解决办法:http://drupal.org/node/192448 ,但这个方法仍然不是很好,它只是用了static的方法,减少重复而已,而且每次页面重新打开的时候,又重新做同样的事了,效率不高。

3.粗略参考一下高手是怎么为drupal 写cache的:http://www.lullabot.com/articles/a_beginners_guide_to_caching_data , 很简单麻,就是static基础上增加cache_set存入数据库。所以我的思路也是这样了(一开始我自己想的是用文件存起来,结果发现读一行的数据库要比打开一个文件快100倍,而且编程更简单)

4.直接打开include/path.inc文件,找到这行

$alias = db_result(db_query(.....", $path, $path_language));

换为:
http://www.trackself.com/code/drupal_get_path.txt
OK, 结果就是从73个查询一下子变为43个了,而且消耗的内存居然少了(不明原因)。

同样的做法,发现了taxonomy_get_term这个家伙也是特别耗查询,居然也有30来个(我的站有好几十个分类),你不用path总不能不用分类吧。

http://api.drupal.org/api/function/taxonomy_get_term/6

于是我用类似的方法也改了taxonomy_get_term,结果现在的查询只余下23个了,还能继续减下去的,只是好像已经没必要了。

Share