Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Extremly Slow Sql Query When 120 000 Products Rate Topic   - - - - -

 
  • Zahhar
  • Junior Member
  • Members
  • Join Date: 01-Nov 08
  • 33 posts

Posted 25 March 2014 - 06:20 PM #1

Hi all!


I have about 120 000 products across 9000 categories, with more then 800 000 references between them (each product belongs to 7 categories in average).

Latest CS-Cart (4.1.3 at the moment) runs on VPS with 4GB RAM, single-core configuration. Cache is stored in the database (mySQL with myISAM tables and mySQLi mode).

Memory_limit for PHP 5.5 is set for 2GB.

Every page takes about 5-10 seconds to load. Bottleneck is SQL queries, that sometimes take up to 30 seconds to build up their data.

For examples, there are such monsters as:

SELECT SQL_CALC_FOUND_ROWS products.*, descr1.product as product, MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price, GROUP_CONCAT(IF(products_categories.link_type = 'M', CONCAT(products_categories.category_id, 'M'), products_categories.category_id)) as category_ids, products_categories.position, IF(shared_descr.product_id IS NOT NULL, shared_descr.product, descr1.product) as product, IF(shared_descr.product_id IS NOT NULL, shared_descr.short_description, descr1.short_description) as short_description, IF(shared_descr.product_id IS NOT NULL, IF(shared_descr.short_description = '', shared_descr.full_description, ''), IF(descr1.short_description = '', descr1.full_description, '')) as full_description, IF(shared_descr.product_id IS NOT NULL, shared_descr.meta_keywords, descr1.meta_keywords) as meta_keywords, IF(shared_descr.product_id IS NOT NULL, shared_descr.meta_description, descr1.meta_description) as meta_description, IF(shared_descr.product_id IS NOT NULL, shared_descr.search_words, descr1.search_words) as search_words, IF(shared_descr.product_id IS NOT NULL, shared_descr.promo_text, descr1.promo_text) as promo_text, IF(shared_prices.product_id IS NOT NULL,MIN(IF(shared_prices.percentage_discount = 0, shared_prices.price, shared_prices.price - (shared_prices.price * shared_prices.percentage_discount)/100)),MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100))) as price, 100 - ((prices.price * 100) / list_price) AS sales_discount FROM cscart_products as products LEFT JOIN cscart_product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = 'ru' LEFT JOIN cscart_product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1 INNER JOIN cscart_products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN cscart_categories ON cscart_categories.category_id = products_categories.category_id AND (cscart_categories.usergroup_ids = '' OR FIND_IN_SET(0, cscart_categories.usergroup_ids) OR FIND_IN_SET(1, cscart_categories.usergroup_ids)) AND cscart_categories.status IN ('A', 'H') LEFT JOIN cscart_ult_product_descriptions shared_descr ON shared_descr.product_id = products.product_id AND shared_descr.company_id = 1 AND shared_descr.lang_code = 'ru' LEFT JOIN cscart_ult_product_prices as shared_prices ON shared_prices.product_id = products.product_id AND shared_prices.lower_limit = 1 AND shared_prices.usergroup_id IN (0, 0, 1) AND shared_prices.company_id = 1 WHERE 1 AND cscart_categories.company_id = 1 AND (products.usergroup_ids = '' OR FIND_IN_SET(0, products.usergroup_ids) OR FIND_IN_SET(1, products.usergroup_ids)) AND products.status IN ('A') AND prices.usergroup_id IN (0, 0, 1) GROUP BY products.product_id HAVING sales_discount > 0 ORDER BY sales_discount desc LIMIT 0, 8

Any advice how to handle such load?
I foresee, that these queries ate too complicated, and optimizing mySQL engine would not help much. Are there any other options to consider?

Boutique digital agency, marketing automation: bergdigital.ch


 
  • Takestock
  • Senior Member
  • Members
  • Join Date: 08-Nov 13
  • 505 posts

Posted 26 March 2014 - 07:02 AM #2

Hi all!


I have about 120 000 products across 9000 categories, with more then 800 000 references between them (each product belongs to 7 categories in average).

Latest CS-Cart (4.1.3 at the moment) runs on VPS with 4GB RAM, single-core configuration. Cache is stored in the database (mySQL with myISAM tables and mySQLi mode).

Memory_limit for PHP 5.5 is set for 2GB.

Every page takes about 5-10 seconds to load. Bottleneck is SQL queries, that sometimes take up to 30 seconds to build up their data.

For examples, there are such monsters as:

SELECT SQL_CALC_FOUND_ROWS products.*, descr1.product as product, MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price, GROUP_CONCAT(IF(products_categories.link_type = 'M', CONCAT(products_categories.category_id, 'M'), products_categories.category_id)) as category_ids, products_categories.position, IF(shared_descr.product_id IS NOT NULL, shared_descr.product, descr1.product) as product, IF(shared_descr.product_id IS NOT NULL, shared_descr.short_description, descr1.short_description) as short_description, IF(shared_descr.product_id IS NOT NULL, IF(shared_descr.short_description = '', shared_descr.full_description, ''), IF(descr1.short_description = '', descr1.full_description, '')) as full_description, IF(shared_descr.product_id IS NOT NULL, shared_descr.meta_keywords, descr1.meta_keywords) as meta_keywords, IF(shared_descr.product_id IS NOT NULL, shared_descr.meta_description, descr1.meta_description) as meta_description, IF(shared_descr.product_id IS NOT NULL, shared_descr.search_words, descr1.search_words) as search_words, IF(shared_descr.product_id IS NOT NULL, shared_descr.promo_text, descr1.promo_text) as promo_text, IF(shared_prices.product_id IS NOT NULL,MIN(IF(shared_prices.percentage_discount = 0, shared_prices.price, shared_prices.price - (shared_prices.price * shared_prices.percentage_discount)/100)),MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100))) as price, 100 - ((prices.price * 100) / list_price) AS sales_discount FROM cscart_products as products LEFT JOIN cscart_product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = 'ru' LEFT JOIN cscart_product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1 INNER JOIN cscart_products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN cscart_categories ON cscart_categories.category_id = products_categories.category_id AND (cscart_categories.usergroup_ids = '' OR FIND_IN_SET(0, cscart_categories.usergroup_ids) OR FIND_IN_SET(1, cscart_categories.usergroup_ids)) AND cscart_categories.status IN ('A', 'H') LEFT JOIN cscart_ult_product_descriptions shared_descr ON shared_descr.product_id = products.product_id AND shared_descr.company_id = 1 AND shared_descr.lang_code = 'ru' LEFT JOIN cscart_ult_product_prices as shared_prices ON shared_prices.product_id = products.product_id AND shared_prices.lower_limit = 1 AND shared_prices.usergroup_id IN (0, 0, 1) AND shared_prices.company_id = 1 WHERE 1 AND cscart_categories.company_id = 1 AND (products.usergroup_ids = '' OR FIND_IN_SET(0, products.usergroup_ids) OR FIND_IN_SET(1, products.usergroup_ids)) AND products.status IN ('A') AND prices.usergroup_id IN (0, 0, 1) GROUP BY products.product_id HAVING sales_discount > 0 ORDER BY sales_discount desc LIMIT 0, 8

Any advice how to handle such load?
I foresee, that these queries ate too complicated, and optimizing MySQL engine would not help much. Are there any other options to consider?

I am no expert in this, but with this number of products and categories even the best VPS with SSD and as much RAM as possible would be slow,

I would also suspect that storing the cache in the database would also be causing extra load on the SQL.

One thing that might help would be to turn on allow persistent sql connections. I took 3 seconds off my page load time on a 5000 product store on a VPS with about the same specs. but this will most likely come with it's own CPU load issue on a VPS of this spec an your 120 000 products

But with a store of this size only a dedicated server with as much CPU and RAM that you can throw at it will solve your issues.

Alan

 
  • sfchost
  • Newbie
  • Members
  • Join Date: 08-Mar 14
  • 3 posts

Posted 02 April 2014 - 12:18 AM #3

Have you enabled the "slow query log" within mySQL? This will help dig into the exact query that killing the performance.
http://planet.mysql....ntry/?id=663131
https://dev.mysql.co...-query-log.html

Also, Percona has a few tools that can take that slow query log, rank your lowest queries and really help to identify the biggest offenders:
http://www.mysqlperf...percona-server/
http://www.percona.c...ery-digest.html

And one thing we've used when needed is Percona's free analyer tool:
https://tools.percon...m/query-advisor

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12075 posts

Posted 02 April 2014 - 05:01 AM #4

Suggest you move the cache to 'file' so that you reduce db contention. Then you probably want to do the query logging suggested above. But you will first want to remove the contention between the lookups and the cached data.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • mink
  • Developer
  • Authorized Reseller
  • Join Date: 03-Oct 12
  • 27 posts

Posted 02 April 2014 - 12:35 PM #5

Hi Zahhar,

The issue can be hardly fixed by MySQL tuning or optimization, however it is possible to integrate your store with advanced cache or/and search systems.
For example, you may go ahead with the default "Searchanise" module which may the product queries much lighter or integrate your store with search engines like Elastica or Sphinx.

If you need more additional information on it, please do not hesitate to contact us on http://www.simtechdev.com/
Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER
LICENSES | DEVELOPMENT | ADD-ONS | DESIGNS | UPGRADES

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12075 posts

Posted 02 April 2014 - 09:31 PM #6

So cs-cart (Simtech Development) is stating that there is no DB conflict in using mysql as the backend cache on large sites?

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • mink
  • Developer
  • Authorized Reseller
  • Join Date: 03-Oct 12
  • 27 posts

Posted 03 April 2014 - 08:47 AM #7

So cs-cart (Simtech Development) is stating that there is no DB conflict in using mysql as the backend cache on large sites?


Actually, by default all installations of CS-Cart uses the "file" backend cache.

As for the "mysql" backend cache type, it hardly works fine in case the site database is big because if main product queries take time, the "mysql" backend cache will only slow them down.


In addition, CS-Cart software supports the "redis" cache type and it should be faster even than the "file" one. For this type of cache it is necessary to install Redis on the server where CS-Cart installed.
Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER
LICENSES | DEVELOPMENT | ADD-ONS | DESIGNS | UPGRADES

 
  • Zahhar
  • Junior Member
  • Members
  • Join Date: 01-Nov 08
  • 33 posts

Posted 03 April 2014 - 09:49 AM #8

Hi and thank you all!

What is done so far:

1. Cache store changed back to default = file
2. Database is tuned with http://mysqltuner.com/ script
3. Time limits are increased to 3600 to prevent timeouts in admin panel.

It made tinks little bit better, but it is still enough. I see main problem in CS-Cart architecture, that makes a real huge amount of very complicated queries (according to slow_query_log), so mySQL can't process them.

Now thinking about separating mySQL to another VPS. It will give me more free RAM on current server to allocate it for redis cache store. Then I'll try to enable Searchanise.

Boutique digital agency, marketing automation: bergdigital.ch


 
  • novitas
  • Member
  • Members
  • Join Date: 11-Feb 11
  • 18 posts

Posted 14 April 2014 - 04:59 AM #9

Zahhar,

What did you endup doing? I'm having similar issues with v4. Extremely slow first time loads. Up to 20 seconds sometimes. After that it's 2-4 seconds for page loads. Some pages are loading more than 500 queries and I was told that is what's causing the problem. Haven't been able to get any help from cs-cart support yet.

 
  • Zahhar
  • Junior Member
  • Members
  • Join Date: 01-Nov 08
  • 33 posts

Posted 14 April 2014 - 07:29 AM #10

Hi Novitas! Currently nothing new beyond named in my last post on April, 3rd. We working on design and development of additional functionality and decided just to move into 2-core server with even more memory (8GB instead of 4GB), to make use of Redis cache. I will report as far as I get any performance results.

Boutique digital agency, marketing automation: bergdigital.ch


 
  • novitas
  • Member
  • Members
  • Join Date: 11-Feb 11
  • 18 posts

Posted 14 April 2014 - 11:17 PM #11

I installed Redis and tried to switch from file to redis, however the site crashed. Any pointers? How did you get redis to work?

Would be very interested to know if switching to that 2-core server helped. Is that a dedicated server or vps?

 
  • novitas
  • Member
  • Members
  • Join Date: 11-Feb 11
  • 18 posts

Posted 15 April 2014 - 11:22 PM #12

Got redis to work, but didn't see a huge (if any) improvement. I really like all the features in cs-cart, however if I'm spending my time trying to optimize it to a workable speed, configuring servers, etc, and still not coming close to the speed of other carts/hosted solutions....what's the point?

 
  • Zahhar
  • Junior Member
  • Members
  • Join Date: 01-Nov 08
  • 33 posts

Posted 15 April 2014 - 11:29 PM #13

Novitas, can you share with me clues about configuring Redis for CS-Cart? What is tech. parameters of your server, and number of products / relations between products and categories? What solutions did you tried with the same amount of products on the similar hardware?

As for me, I see point of CS-Cart in its unlimited customization possibilities without much pain. Also, its backend is good (it is far from perfect, especially compared to previous version, now I see 2 steps backwards, but still it is better then UI of its rivals), and we have developers support for reasonable price. It makes sense for me.

Boutique digital agency, marketing automation: bergdigital.ch


 
  • novitas
  • Member
  • Members
  • Join Date: 11-Feb 11
  • 18 posts

Posted 19 April 2014 - 06:42 PM #14

Zahhar,

I turned off redis and switched back to "file". I didn't see any improvement.