Kunena 7.0.9 & Kunena 6.4.14 – Security Updates Released

The Kunena team has announce the arrival of Kunena 7.0.9 [K 7.0.9] in stable which is now available for download as a native Joomla extension for J! 5.4.x/6.0.x./6.1.x. This version addresses most of the issues that were discovered in K 6.2 / K 6.3 / K 6.4 and issues discovered during the last development stages of K 7.0

Before posting new topics in this category K 1.5.x Support: Please read this first.

Question Kunena 1.5.11 Query optimization to improve performance of large forum

More
16 years 2 weeks ago - 16 years 2 weeks ago #61755 by unixoid
Joomla Version: 1.5.18 Stable
Kunena Version: 1.5.11
Mysql version: 5.0.77-log
PHP Version: 5.2.14

We are running site with about 10k registered users. At peak time, we see anywhere between 150-200 active users, i.e. users whos session has not expired. The fb_messages table has about 2.2 million records in it.

We are seing performance problem with few queries. The one that takes most server time comes from default_ex/showcat.php. The query is below:
Code:
# Query_time: 4 Lock_time: 0 Rows_sent: 20 Rows_examined: 799532 SELECT t.id, MAX(m.id) AS lastid FROM jos_fb_messages AS t INNER JOIN jos_fb_messages AS m ON t.id = m.thread WHERE t.parent='0' AND t.hold='0' AND t.catid='2' AND m.hold='0' AND m.catid='2' GROUP BY m.thread ORDER BY t.ordering DESC, lastid DESC LIMIT 0, 20;

As you might note it looks at almost 800k rows and returns just 20 (due to pagination). The problem with this query is that it uses file based temp table and filesort. Attached is the explain plan from JetProfiler:



We had to point mysql’s tmpdir to /dev/shm (memory-based file system), due to file system not being able to keep up with query demands at peak load.

After that change, the query performance increased, its response decreased to about 1s from about 6s. However, this query occupies about 3x more database time compared to the next busiest query.
I am looking to understand what business function does this query do and any recommendations to improve its performance. I looked at newest code in showcat.php from kunena 1.6 and did not see any changes to this particular query.

Some ideas that could or could not be implemented I this query is to add more limiting range in the where clause to not scan all entries, but look at, say highest 50% of m.thread or m.id. Not sure if it will help the business case for this query.
Last edit: 16 years 2 weeks ago by unixoid. Reason: Moved attachment inline

Please Log in or Create an account to join the conversation.

More
16 years 2 weeks ago - 16 years 2 weeks ago #61790 by Matias
As really quick fix (althought small one) this should help you to get about 30% performance improvement on that query:
Code:
ALTER TABLE `jos_fb_messages` ADD INDEX `catid_parent` ( `catid`,`parent` );

To make the query really fast, we are making some changes into our database model for Kunena 1.7.
Last edit: 16 years 2 weeks ago by Matias.
The following user(s) said Thank You: ChaosHead

Please Log in or Create an account to join the conversation.

More
16 years 2 weeks ago #61803 by ChaosHead

Please Log in or Create an account to join the conversation.

More
16 years 2 weeks ago - 16 years 2 weeks ago #61804 by Matias
Optimization was missing before RC3 (which will be out shortly).

In Kunena.com optimization seems to result ~10% better performance inside categories and index page.

This is what needs to be changed for Kunena 1.6:
Code:
ALTER TABLE `jos_kunena_messages` DROP INDEX `catid`; ALTER TABLE `jos_kunena_messages` DROP INDEX `parent`; ALTER TABLE `jos_kunena_messages` ADD INDEX `catid_parent` ( `catid`, `parent` );
Last edit: 16 years 2 weeks ago by Matias.
The following user(s) said Thank You: ChaosHead, unixoid

Please Log in or Create an account to join the conversation.

More
16 years 2 weeks ago #61955 by unixoid
I have added combined parentid+catid index as it was suggested, the query performance degraded by 49%. I looked at the explain plan, and found that instead of new parentid_catid index, mysql chose catid only. I then dropped parentid and catid indexes, the mysql chose parentid_catid index and performance improved by 24%. Thanks for reql quick tuning recommendation.

Here is the code that was run:
Code:
ALTER TABLE `jos_fb_messages` ADD INDEX `catid_parent` ( `catid`,`parent` ) ALTER TABLE `jos_fb_messages` DROP INDEX `catid`; ALTER TABLE `jos_fb_messages` DROP INDEX `parent`;

explain plan for new index:
Code:
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t ref PRIMARY,hold_time,parent_hits,liko_id,catid_parent catid_parent 9 const,const 33507 Using where; Using temporary; Using filesort 1 SIMPLE m ref thread,hold_time,catid_parent thread 5 dev_pewter.t.id 22 Using where

Does anyone know is there a best way to break the query into two? I really don't like that most of the time is spent dealing with file-based temp table. The query profile after index change shows that the slowest step is still remains copying to temp table, which dropped down from about 4.4s to 3.8s on average of 10 tests.

Please Log in or Create an account to join the conversation.

More
16 years 2 weeks ago - 16 years 2 weeks ago #62021 by fxstein
Breaking up the query is no solve. You can try it yourself. Even if you eliminate the join (incorrect results), the index lookup is still there.

You should definitely consider Kunena 1.6 for your site. The overall performance improvements have been significant and the query volume has been cut down dramatically. It will lower the load on your mysql instance significantly.

For 1.7 we are working on a new thread table design that takes care of these issues in a different way.

Having said that, the query in question on our server runs in less than 0.07 seconds. Server setup definitely plays a role if you have a large forum with millions of posts.

We love stars on the Joomla Extension Directory . :-)
Last edit: 16 years 2 weeks ago by fxstein.

Please Log in or Create an account to join the conversation.

Time to create page: 0.258 seconds