Kunena 6.3.0 released

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

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
13 years 7 months ago - 13 years 7 months ago #1 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.
Attachments:
Last edit: 13 years 7 months ago by unixoid. Reason: Moved attachment inline

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

More
13 years 7 months ago - 13 years 7 months ago #2 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: 13 years 7 months ago by Matias.
The following user(s) said Thank You: ChaosHead

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

More
13 years 7 months ago #3 by ChaosHead

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

More
13 years 7 months ago - 13 years 7 months ago #4 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: 13 years 7 months ago by Matias.
The following user(s) said Thank You: ChaosHead, unixoid

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

More
13 years 7 months ago #5 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
13 years 7 months ago - 13 years 7 months ago #6 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: 13 years 7 months ago by fxstein.

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

More
13 years 7 months ago #7 by unixoid
Do you have any insight on your server set up, especially to support this table. Would MyISAM be preferrable or Innodb, how large are your buffers?

By breaking up the query I was thinking for ways to mysql to not use filesort. It is my understanding that the group by clause is forcing mysql to not use in-memory temp tables, but write them to disk, then sort the entries there.

If I have 2 queries and join them in php I was hoping that neither one would be processed with filesort.

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

More
13 years 7 months ago #8 by Matias
I would take InnoDB for many reasons:

1) it doesn't get corrupted on power failures (lost all data in MyISAM table -- a few times)
2) you can keep large parts of the tables in memory
3) it's generally faster, except on SELECT COUNT(*)

It does have some limitations, but there's no need to use InnoDB in all your tables.

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

More
13 years 7 months ago #9 by fxstein
InnoDB is absolutely the choice for concurrency. Table level locks in MyISAM will kill your site when concurrence increases. InnoDB might be slower on some single stream queries, but when you add mixed read/write and concurrent users, InnoDB is the clear choice.

What I would suggest to start is to check you MySQL server setup. See here: www.day32.com/MySQL/

Make sure you have enough memory for the buffers in the RIGHT places. Also enable query caching in MySQL.

To improve that particual query the easiest thing would be to profile your data and see how much is really every going to be needed. If you have 2M records in that table, how many new get added every day/week/month.
How many pages of threads do you really need in showcat. Will people every go to page #200+ to look up threads or is it more likely that they will use search for that.
If so a simple timelimit on that page might be all it takes to make it run very fast. I would experiment with 1 year, 6 month and 3 month time limits. For now this could be hard coded in there if that works for you.

For Kunena 1.7 (already in development) the new thread structures will eliminate that type of query alltogether.

Hope this helps!

We love stars on the Joomla Extension Directory . :-)
The following user(s) said Thank You: unixoid

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

More
13 years 7 months ago - 13 years 7 months ago #10 by fxstein
Here are our current stats:
Code:
-- MYSQL PERFORMANCE TUNING PRIMER -- - By: Matthew Montgomery - MySQL Version 5.0.90-log x86_64 Uptime = 78 days 19 hrs 16 min 52 sec Avg. qps = 138 Total Questions = 944369290 Threads Connected = 12 Server has been running for over 48hrs. It should be safe to follow these recommendations To find out more information on how each of these runtime variables effects performance visit: http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html Visit http://www.mysql.com/products/enterprise/advisors.html for info about MySQL's Enterprise Monitoring and Advisory Service SLOW QUERIES The slow query log is enabled. Current long_query_time = 1 sec. You have 48519 out of 944369312 that take longer than 1 sec. to complete Your long_query_time seems to be fine BINARY UPDATE LOG The binary update log is NOT enabled. You will not be able to do point in time recovery See http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html WORKER THREADS Current thread_cache_size = 10 Current threads_cached = 9 Current threads_per_sec = 0 Historic threads_per_sec = 0 Your thread_cache_size is fine MAX CONNECTIONS Current max_connections = 256 Current threads_connected = 9 Historic max_used_connections = 99 The number of used connections is 38% of the configured maximum. Your max_connections variable seems to be fine. MEMORY USAGE Max Memory Ever Allocated : 963 M Configured Max Per-thread Buffers : 1 G Configured Max Global Buffers : 506 M Configured Max Memory Limit : 1 G Physical Memory : 3.86 G Max memory limit seem to be within acceptable norms KEY BUFFER Current MyISAM index space = 64 M Current key_buffer_size = 24 M Key cache miss rate is 1 : 875488 Key buffer fill ratio = 55.00 % Your key_buffer_size seems to be too high. Perhaps you can use these resources elsewhere QUERY CACHE Query cache is enabled Current query_cache_size = 96 M Current query_cache_used = 69 M Current query_cache_limit = 1 M Current Query cache Memory fill ratio = 72.68 % Current query_cache_min_res_unit = 2 K MySQL won't cache query results that are larger than query_cache_limit in size SORT OPERATIONS Current sort_buffer_size = 2 M Current read_rnd_buffer_size = 256 K Sort buffer seems to be fine JOINS Current join_buffer_size = 2.00 M You have had 242444 queries where a join could not use an index properly You have had 820 joins without keys that check for key usage after each row You should enable "log-queries-not-using-indexes" Then look for non indexed joins in the slow query log. If you are unable to optimize your queries you may want to increase your join_buffer_size to accommodate larger joins in one pass. Note! This script will still suggest raising the join_buffer_size when ANY joins not using indexes are found. OPEN FILES LIMIT Current open_files_limit = 8458 files The open_files_limit should typically be set to at least 2x-3x that of table_cache if you have heavy MyISAM usage. Your open_files_limit value seems to be fine TABLE CACHE Current table_cache value = 4096 tables You have a total of 1233 tables You have 2479 open tables. The table_cache value seems to be fine TEMP TABLES Current max_heap_table_size = 128 M Current tmp_table_size = 32 M Of 28316715 temp tables, 19% were created on disk Created disk tmp tables ratio seems fine TABLE SCANS Current read_buffer_size = 128 K Current table scan ratio = 311 : 1 read_buffer_size seems to be fine TABLE LOCKING Current Lock Wait ratio = 1 : 1339 You may benefit from selective use of InnoDB. If you have long running SELECT's against MyISAM tables and perform frequent updates consider setting 'low_priority_updates=1' If you have a high concurrency of inserts on Dynamic row-length tables consider setting 'concurrent_insert=2'.

Hope this helps!

We love stars on the Joomla Extension Directory . :-)
Last edit: 13 years 7 months ago by fxstein.

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

Time to create page: 0.551 seconds