How To Improve Performance of Highly Commented WordPress Blogs �R�����g�A�E�g�̍����p�t�H�[�}���X����コ�����@�ɂ��Ă�WordPress Blogs
Most of highly trafficked and highly commented wordpress blogs rely upon some smart caching solution or another.�قƂ�ǂ̐l�g�����Ɣ��ɍ��x�Ɉˑ����邢�����̃u���O�ɃR�����gWordPress�̃X�}�[�g�L���b�V���܂��͕ʂ̉�����ł��B However it may not be enough to prevent slowing down your server if your post(s) are heavily commented upon.�����������h�����߂ɏ\���Ȃ��Ƃ��ł��Ȃ��ꍇ�͌������Ă���T�[�o�[�̓��e�i�b�j�́A���Ȃ�̃R�����g�ɂ��܂��B This is because smart caching solutions re-create the cache whenever a new comment is posted.����́A�X�}�[�g�L���b�V���̃\�����[�V�������č쐬����Ƃ��ɂ́A�L���b�V���ɐV�����R�����g���f�ڂ���܂��B Here is a simple solution in three steps.���Ɏ����̂́A�ȒP�ȉ������3�̎菇�����s���܂��B
Steps:�X�e�b�v�F
- Install (and activate)�C���X�g�[���i���A�A�N�e�B�u���j Wp-Cache 2 WP�B���ꏊ2 plugin.�������ł��B I have excellent experience with it for over a year.���͑f���炵���o��������1�N�ȏ�ł��B
- Modify wp-cache-phase2.php (one of the plugin files) to comment / delete the line:�ύX��WP -�L���b�V��- phase2.php �i�������̂����ꂩ�̃t�@�C���j���R�����g/�폜���čs�F
add_action('comment_post', 'wp_cache_get_postid_from_comment', 0);add_action �i ' comment_post ' �A ' wp_cache_get_postid_from_comment ' �A 0 �j ; - Set the cache expiration time to 2 hours or more.�L���b�V���̗L������ݒ肷�鎞�Ԃ�2���Ԉȏ�ł��B This can easily handle a slashdot effect without breaking a sweat.����́A�X���b�V���h�b�g�̌�ʂ�e�Ղɏ�������j�������ƂȂ����������B
The change in step 2 ensures that the pages are not regenerated everytime a new comment is posted.���̕ύX�ɂ��A�X�e�b�v2�ōĐ�����Ȃ���everytime�̃y�[�W�ɐV�����R�����g���f�ڂ���܂��B They are however regenerated after the expiration of cache.�������ނ�̓L���b�V���̗L���Ԃ�����������ɍĐ������܂��B This time lag saves an enormous amount of sql query when a post is heavily commented.���̎��Ԃ̂���Z�[�u�͖c��Ȑ���SQL�N�G�������s����Ƃ��ɂ͂��Ȃ�̃R�����g�𓊍e���܂��B
Filed under��o����� CMS Software CMS�\�t�g�E�F�A , �A Headline News�j���[�X�̌��o�� , �A How To�ǂ̂悤�� , �A PHP PHP�� , �A Pro Blogging�v��Blogging , �A Tech Note�Z�p�̃m�[�g , �A Web�E�F�u , �A Web Services Web�T�[�r�X , �A WordPress WordPress�� | |
| |
RSS 2.0 RSS 2.0�� | |
Trackback�g���b�N�o�b�N this Article |���̋L��|
Email this Article�d�q���[�����̋L��
You may also like to read��ǂނ悤�ɂ��邱�Ƃ��\ |





































April 27th, 2006 at 10:49 am 2006�N4��27��̌ߑO7:49
People like instant gratification.�l�X�̂悤�ȃC���X�^���g�����ł��B If somebody makes a comment on a website, they expect it to show up immediately.�N���ɉ����R�����g������E�F�u�T�C�g�ɂ́A������\������ɂ����ɂ������҂��܂��B Otherwise, the commentor will be discouraged from posting a comment in the future.����ȊO�̏ꍇ�A���_�����commentor �A��������R�����g�𓊍e���܂��B
Because of this, I think that another solution is needed.���̂��߁A�����v���ɁA������̉����K�v�ɂȂ�܂��B
April 27th, 2006 at 12:51 pm 2006�N4��27���12:51 pm��
When the choice is between providing instant gratification versus making the site available, isn�ft the solution clear?�Ƃ��ɂ����ɓ������сA�I�Ԃ̂͑��[�J�[�̊Ԃɒ���T�C�g�̂����p�́A���m�ȉ�����ł͂Ȃ��̂ł����H
I don�ft think expecting comments to appear immediately is something which users have come to expect as many sites today have manual or semi-manual moderation policy.��҂Ƃ͎v��Ȃ������ɃR�����g��\������ɂ͉�������҂��郆�[�U�[�����鍡��͂ł��邾�������̃T�C�g�̊Ǘ��|���V�[�}�j���A���܂��͔��}�j���A���ł��B A clear statement explaining the situation should address the expectations.�m�ɐ����́A�A�h���X�̊�҂ɏ�������Ă��܂��B
April 27th, 2006 at 10:53 pm 2006�N4��27���10:53 pm��
Have you implemented this on a public site that I can see it in action on?�����ɂ́A�����̎������̃T�C�g���Q�Ƃ��Ď��ɑΏ����邱�Ƃł����H I noticed when I posted that you don�ft use it on this one.�C�t�����Ƃ��Ɏ����f���Ŏg�p����K�v�͂���܂��A����1�ł��B I am really curious about the type of site you feel this would be helpful on.���͖{���ɍD��S��������T�C�g�̃^�C�v�ɂ��ẮA����͏�ɖ𗧂B
My feeling is that the number of comments on a weblog is going to be very low.���̋C�����́A�����̃R�����g�́A�E�F�u���O�͔̂��ɒႢ���낤�B But, even if somehow the volume of comments becomes a problem, wouldn�fta better solution be to move the comments onto a seperate page?�������A���Ƃ����炩�̖��̉��ʂ��R�����g�����A���ǂ�������wouldn'ta�Ɉړ�����ɃR�����g��ʂ̃y�[�W�ł����H This would get rid of most of the read-only load as well as the read-write load due to comments because you are only sending that page to the small fraction of people that care about the comments in the first place.����͂قƂ�ǂ̎�菜���A�ǂݎ���p�̕��ׂ�read - write�����łȂ��A���ׂ̂��߂ɃR�����g����Ă��邽�߁A���̃y�[�W�݂̂𑗐M��������͂邩�ɏ����̐l�X���P�A�ɂ��ẮA�R�����g�̍ŏ��̏ꏊ�ł��B
Anyway, I just think that there are so many other possibilities to improve performance before taking a step that has such a negative impact on the user experience.�Ƃɂ����A�������Ǝv�����̉\�������ɂ�������̃p�t�H�[�}���X����シ���������O�ɂ��̂悤�Ȕے�I�ȉe����^���邱�Ƃ́A���[�U�[�̗����ł��B
April 28th, 2006 at 12:17 pm 2006�N4��28���12:17 pm��
> My feeling is that the number of comments on a weblog is going to be very low. > "�}�C����̂́A�����̃R�����g�́A�E�F�u���O�͔̂��ɒႢ���낤�B
Again this is not a solution for oridinary situations.�Ăт��̏ł͂Ȃ�oridinary����\�����[�V��������܂��B There are certain popular blogs which elicit lots of comments, especially more when you break a story / get slashdotted etc. usmagazine is one such site.����̐l�C�u���O����o���ɂ́A��������̃R�����g�A���ɑ��̘b�𒆒f����Ƃ���/�擾��usmagazine slashdot��ʂ̋]���ɂ͂��̂悤�ȃT�C�g��1�ł��B
I used this technique for a limited time on this blog with good results.���͂��̃e�N�j�b�N�́A����ꂽ���Ԃ����̃u���O�ŗǂ����ʂł��B
> But, even if somehow the volume of comments becomes a problem, wouldn’ta better solution be to move the comments onto a seperate page? >�������A���Ƃ����炩�̖��̉��ʂ��R�����g�����A����wouldnâ € ™���悢��������ړ�����ɂ̓R�����g��ʂ̃y�[�W�ł����H
How are you going to do that within WordPress framework?������s���ɂ͂ǂ̂悤�ɍs�����Ƃ�WordPress�̃t���[�����[�N�ł����H
> Anyway, I just think that there are so many other possibilities to improve performance >�Ƃɂ����A�������Ǝv���\�������ɑ����̃p�t�H�[�}���X����コ����
Please let me know how you plan to optimize performance of a heavily commented site without slowing down page re-generation after comments?���A�����������p�t�H�[�}���X���œK�������@���v�悵�ăT�C�g�ɃR�����g��傫���݉����ăy�[�W���Đ���������̃R�����g�ł����H
April 28th, 2006 at 2:36 pm 2006�N4��28���2:36 pm��
Sorry to be a little dense, but does this hack actually make the comments not appear on individual post pages until the cache expires?���g���Z��ז����āA���̃n�b�N�킯�ł́A���ۂɌX�̓��e�y�[�W�̃R�����g�ɂ͕\�������܂ŁA�L���b�V���̗L���������ł����H Or do the number of comments indicated on the main page simply not update to match the actual number of comments visible on individual comment pages?�܂��͂ɂ́A�R�����g�̐������̃��C���y�[�W�Ɏ�����Ă��Ȃ��X�V�v���O�����̎��ۂ̐��̃R�����g���ɍ��킹�ČX�̃R�����g�����̃y�[�W�ł����H
jf
April 28th, 2006 at 9:23 pm 2006�N4��28��9:23 pm��
The new comments are published as soon as the cache expires.�V�����R�����g�͂����ɃL���b�V���̗L���������Ƃ��Č��J����Ă��܂��B So if your cache is set to 30 minutes then you get to see the new comments every 30 minutes instead of instantly.�������Ȃ��̃L���b�V����30���ɐݒ肳���͂��A�ڍׂɂ��ẮA�V���ȃR�����g���������ɁA 30�����ɑ����ɂ��܂��B
Probably this is what was not clear to Brian as I am still trying to understand why he thinks it would be such a bad thing.�����炭����́A�ǂ̂悤�ȃu���C�A���͂Ȃ��Ƃ��Ė��m�ɂ��悤�Ǝ��͂܂��ނ̍l���𗝉����邱�Ƃ��Ȃ����̂悤�Ȉ������Ƃł��B
April 29th, 2006 at 7:27 am 2006�N4��29��̌ߑO7��27��
It�fs not a terrible thing, but it�fs not right for every site.����͂Ђǂ����Ƃ��A����͂��Ȃ����������ׂẴT�C�g�ł��B For sites where the community and discussion aspect is an important part of why people visit, changing the situation from comments-appear-instantly to comments-appear-after-a-pause can turn people off and eliminate one of the reasons that they came and visited in the first place.�R�~���j�e�B��f�B�X�J�b�V�����T�C�g�ł́A�A�X�y�N�g�́A�Ȃ��l�X���K���̏d�v�ȕ����́A�R�����g��ύX���Ă���̏��ɕ\�������-�R�����g-�\�������-�ꎞ��~������ɂ���l�X�́A�d���I�t�̗��R��1��r�����ė����ƖK��̍ŏ��̏ꏊ�ł��B
Of course, having a pause before comments appear is better than having a site that doesn�ft work.�������A�R�����g�\������邱�Ƃ��ꎞ��~����O�ɃT�C�g�������͂܂��͋@�\���܂���B But not everybody who is looking to improve WP�fs performance is at a place where their site is crashing constantly.�������A�N�����Ȃ�who�T�C�Y��WP�̃p�t�H�[�}���X����コ���邽�߂̏ꏊ�́A��Ɏ����̃T�C�g���N���b�V�����܂��B My site for instance is still chugging along fine performance-wise, but I�fve been warned by my Web host that it�fs starting to take up more server resources than they�fre comfortable with, so I�fm looking at ways to improve performance.���Ƃ��Ύ����̃T�C�g�ɂ́A�܂���C��݂ɉ����̌����ȉ��Z-�����ȁA�������A���͎��̃E�F�u�z�X�g����x������̂��J�n���đ��̃T�[�o�[�̃��\�[�X���������ނ�͉��K�ɁA���͂������コ�����@��͍�����B Still, because my site visitors enjoy using the comments section to talk to one another more or less in real time — and because, I suspect, a long pause after commenting would result in fewer visits on their part (and thus less revenue to me) I wouldn�ft implement a technique like yours except as a last resort (ie if my Web host got fed up and was threatening to shut me down).����ł��A�����̃T�C�g�ɖK����y���ނ��߂̃R�����g���g�p���āA 1�̃Z�N�V������ʂ̘b�����鑽���ꏭ�Ȃ�������A���^�C����-�ƂȂ��Ȃ�A���̗e�^�ҁA�ꎞ��~������A�����R�����g�����Ȃ����ʓI�ɖK�₵�ăp�[�g�i����䂦���Ȃ��������C���j���͂��Ȃ������{�����@�������Ă͍Ō�̎�i�Ƃ��Ă̂悤�ȁi�܂�͂��肷��悢�̃E�F�u�z�X�e�B���O�T�[�r�X�ɋ����d�b������Ƃ́A���C���R���s���[�^���V���b�g�_�E���j �B Still, I�fm sure there are plenty of blogs for whom discussion and comments are not key features of the site, and the technique you outline would be very helpful to them.����ł��A���͂����ƒN�ɂ́A��������̃u���O�̋c�_��R�����g�̎�ȓ����́A����̃T�C�g�ɃA�N�Z�X���A���̎�@���A�E�g���C���͑�Ϗ�����܂����Ă��܂��B
jf
May 4th, 2006 at 2:44 pm 2006�N5��4���2:44 pm��
[...] Falls Ihre Seite laufend mit neuen Kommentaren überschüttet wird, so sollten Sie auf eine Installation der Caching-Funktion verzichten oder diese zumindest nicht im �gAuslieferzustand�h einsetzen. [...]�̑�C�[��seite überschüttet wird laufend mit neuen kommentaren�̂ŁA�C���X�g�[��sollten sie auf eine der�L���b�V��-�t�@���N�V����verzichten�I�[�f��diese zumindest nicht�C��" auslieferzustand " einsetzen �B Da die Cache-Dateien in diesem Fall eine zu kurze Gültigkeitsdauer haben, könnte die Installation Ihren Server mit den zusätzlichen Aufgaben überlasten (oder zumindest nicht entlasten).�_���ʃL���b�V��- dateien �A�H��diesem eine zu kurze gültigkeitsdauer haben �A könnte���ʃT�[�o�[�C���X�g�[��mit ihren aufgaben�f��zusätzlichen überlasten �i�I�[�f��zumindest nicht entlasten �j �B Sollten Sie trotzdem nicht auch ein Caching verzichten wollen, dann können Sie mit dem folgenden kleinen Hack für Abhilfe sorgen. sollten sie trotzdem nicht ein�L���b�V��verzichten�I�b�V���a�сA dann können sie mit��dem folgenden��abhilfe sorgen für kleinen�n�b�N�ł��B Damit wird die Aufbereitung der Caching-Seite nicht von neuen Beiträgen oder Kommentaren abhängig gemacht, sondern erfolgt zeitgesteuert. damit��wird����aufbereitung der�L���b�V��- seite nicht�t�H��neuen beiträgen�I�[�f��kommentaren abhängig gemacht �A sondern erfolgt zeitgesteuert�ł��B Der Nachteil: neue Kommentare oder Beiträge werden nicht sofort, sondern erst nach der zeitbasierten Löschung des Caches sichtbar. der nachteil �F�m�C�Gkommentare�I�[�f��beiträge werden nicht sofort �A sondern nach der zeitbasierten löschung�ȑO�f�L���b�V��sichtbar �B [...]
November 17th, 2006 at 2:41 pm 2006�N11��17���2:41 pm��
Thanks for the tips.�q���g�Ă���Ă��肪�Ƃ��B I am not sure this will help because this looks like suitable for blogs with a lot of comments.���͂킩��Ȃ�����̓w���v�ɓK���Ă��邽�߁A���̃u���O�̂悤�ɁA��������̃R�����g�͂���܂���B
My problem is a little different, not so much on comments.���̖��͏����قȂ�A�Ƃ������̓R�����g�͂���܂���B My blog is having too many visitors, thus have too many processes running at the same time.�u���O�����܂�ɂ������̗���҂́A���̂悤�ɂ��܂�ɂ������̎��ԂƓ����v���Z�X�Ŏ��s����Ă��܂��B How to optimize this?������œK�������@�ł����H
November 17th, 2006 at 10:21 pm 2006�N11��17��10:21 pm��
If this tip doesn�ft help then you are pretty much due for a dedicated server�����A���̃`�b�v�͂���܂���w���v���͂��A���Ȃ������Ȃ�̂��߂ɂ͐�p�̃T�[�o�[
November 18th, 2006 at 12:48 pm 2006�N11��18���12:48 pm��
[...] Since the machine was limited by CPU, I decided to fire up DTrace to see where the httpd process was spending it�fs time. [...]�͐�������Ĉȗ��A�}�V����CPU �A���ɉ��N�������Ƃ����߂�dtrace�����ẮA httpd�v���Z�X�́A�x�o�̎��Ԃł��B The DTrace results indicated that Apache was spending a considerable amount of time compiling PHP pages, and issuing queries to the back-end database. Apache��dtrace���ʂ������Ă���̂́A���Ȃ�̎��Ԃ��₵�ăR���p�C��PHP�̃y�[�W�A����уN�G���s���A�o�b�N�G���h�̃f�[�^�x�[�X�ł��B Since I only update my blog a few times each week, I started to wonder if there was a way to turn the pages I created in Wordpress into static content.�ȗ����͎���blog�̍X�V�𐔉�A�e�T�Ԉȓ��ɁA���n�߂ă����_�[��L��ɂ����@���������ꍇ�ɍ쐬���ꂽ�y�[�W����WordPress��ÓI�ȃR���e���c�ł��B After reading through a variety of wordpress resources, I came across the wordpress cache #2. WordPress�̂�ǂ�ŗl�X�Ȏ�������āA�����S�̂�WordPress�̃L���b�V���� 2 �B This super useful plugin will create a static represetnation of each dynamically generated page, and serve that file instead of the page that wordpress woudl dynamically generate.���̃X�[�p�[�֗��ȃv���O�C�����쐬����ÓI���I�ɐ�����represetnation�̊e�y�[�W�A����уT�[�r�X�����̃t�@�C����WordPress�̑���ɁA�y�[�W�I�ɐ�������Ƃ��܂��B Once I got wp-cache2 installed, the results were right on par with what I orginally thought they should be: [...]���͈�x��WP - cache2�C���X�g�[������ƁA���̌��ʂ́A�E��p�[�ƍl����Steve���ŏ��Ȃ�Ȃ��F [...]
January 1st, 2007 at 12:23 am 2007�N1��1��̌ߑO6:23
[...] I recommend it over external caching engines like eAccelerator because it is senstive to changes in WordPress content and will automatically refresh the cache. [...]���Ƃ�������eaccelerator���O���̃L���b�V���G���W���̂悤�Ȃ��Ƃ�senstive���ύX����邽�߁A WordPress�̃R���e���c�Ƃ͎����I�ɍX�V���ăL���b�V�����N���A���܂��B However it has a downside.����������ɂ́A�}�C�i�X�ł��B On highly commented sites the effects of caching is negated because of frequent cache refreshes.�R�����g�A�E�g�T�C�g��̉e���������ے�̂��߂̃L���b�V�����p�ɂɃL���b�V�����X�V���܂��B This can be addressed by this tip: How to improve performance of highly commented WordPress blogs [...]���̂��Ƃ����g�ނׂ����̃q���g�F�̍����p�t�H�[�}���X����コ�����@�ɂ��ẴR�����gWordPress��blogs [...]
March 20th, 2007 at 8:18 pm 2007�N3��20��͌ߌ�5:18
Would you have any tips for configuring WP-Cache 2 with interactive plugins like GamerZ PostRatings, or comment karma?�悤�ɐݒ���s�����߂̃q���g������WP�B���ꏊ2���̃v���O�C���̂悤�ȃC���^���N�e�B�u��gamerz postratings���A�܂��̓R�����g�̃J���}�̂ł����H
I�fve tried using the mfunc mods in my designs, but they never seem to work�c do you know if a mfunc has to be within a if function_exists call?������������mfunc�g�p���āA���̃f�U�C�������ǁA��悤�Ɏd����m���āc mfunc�ꍇ�ɂ�function_exists���������ꍇ�ɂł����H
This is driving me nuts.����͎��̉^�]�i�b�c�ł��B
Eric�G���b�N
May 1st, 2007 at 8:34 am 2007�N5��1��͌ߑO8��34��
Whilst I don�ft have a high volume of comments across all posts on my blog, there are 2 posts which have a combined total of more than 1200 comments and this seems to be bogging down the site, or at least the loading of those 2 pages.�����Ă��Ȃ��Ȃ����ʂ̃R�����g���S�̂��ׂĂ̋L�����u���O�ɂ́A���v2�̋L���ł́A 1200�ȏ�̃R�����g�ƁA����bogging�_�E������Ǝv����T�C�g�A�܂��͂����̏��Ȃ��Ƃ�2�ǂݍ���ł��܂��y�[�W���������������B I installed wp-cache but since installing I have also started getting internal server 500 errors for one of the posts.�����C���X�g�[����WP�B���ꏊ���C���X�g�[�����������͏A�w���̓����T�[�o�[��500�̃G���[���n�߂��̂����ꂩ�̓��e�ł��B Is your solution the only way of of speeding up these pages?������͂��Ȃ��̃X�s�[�h�A�b�v����B��̕�@�́A�����̃y�[�W�̂ł����H
May 2nd, 2007 at 10:58 am 2007�N5��2���10:58��
You can always buy a bigger and better server / load balance it, also use memcached, eAccelerator etc. Each of them works in different ways to improve performance.�傫�����邱�Ƃ��ł��܂��w���ƁA��ɂ��ǂ��T�[�o�[/���׃o�����X�ɂ́A�g�p�����memcached�܂��A�����̂��ꂼ���eaccelerator�̃p�t�H�[�}���X����コ���邳�܂��܂ȕ�@�œ��삵�܂��B
You may want to read this article for details:���̋L�����{�����邱�Ƃ��ł��܂����Q�Ƃ��Ă��������F
5 Golden Tips For WordPress Performance Optimization / Slashdot-Digg Protection 5������WordPress�̃p�t�H�[�}���X���œK�����邽�߂̃q���g/�X���b�V���h�b�g-����ی�