Archive for December, 2008:

Query Log Released

0

Query Log for Zen Cart is open source, simple tool for monitoring performance of SQL queries. Depending on configuration it will display or save all executed queries sent to database together with information how much time each query took and which page and session executed it. With Query Log and some SQL knowledge You can improve performance of Your Zen Cart store.

At this moment there are two components:

  • Basic Logger – it’ll display to trusted users all logged queries in Zen Cart shop footer.
  • Database Logger – it’ll save all logged queries to database.

Demo Stores

Because Database Logger does not display anything to users no demo store is available for it.

Here’s demo store for Basic Logger: Basic Logger Demo Store

Basic Logger

Basic Logger for each page request logs all queries sent to database and displays them to trusted users in page footer together with time each query took. It will mark with red color queries that take much more time then average. See screencast to see it in action.

Note: Basic Logger is based on contribution made by Chemo for osCommerce, We just added few features to it.

Database Logger

Database Logger does everything that Basic Logger do. In addition it also saves all queries from all page requests of all visitors in database table. You can then execute various queries to check which queries should be optimized, which pages generates most queries, what is average time spent in database etc.

Database Logger is as fast as possible, it uses MyISAM tables without primary key and indexes to store queries (this means that MySQL server does not spend time updating lookup tables). Also, if MySQL ver. 5.0 or later is available You can use Archive storage engine to compress logs (installation script provides two versions of sql patches, one for MySQL ver. 5.0 or later, and one for earlier versions).

Warning: before turning on Database Logger make sure that You know what You’re doing. Storing all queries in database can take huge amounts of disk space.

You can do various things with query_log table, below are few simple use cases.

To list slowest queries execute:

SELECT *
FROM query_log
ORDER BY time DESC
LIMIT 100

You can check what is average time spent in database for each type of page (product_info, index, advanced_search_results etc.):

SELECT page, AVG(time) AS ‘average_time’
FROM query_log
GROUP BY page
ORDER BY average_time DESC

Listing queries executed on ‘product_info’ page that takes more then 0.1 sec to complete:

SELECT *
FROM query_log
WHERE page = ‘product_info’
AND time >= 0.1

Screencast

Here’s screencast showing how to install and use Query Log:

Download

Here You can download Query Log compatible with all 1.3.x Zen Cart versions.

Download Query Log

Installation

Requirements:

  • You can use Query Log with any version of Zen Cart 1.3.x.
  • PHP >= 4.x is required.
  • Query Cache is required. If You don’t want to use Query Cache You have to change includes/classes/db/mysql/query_factory.php to use Query Log

Query Log is quite easy to install. First You need to download it. After that extract it with Winzip or something similar and follow instructions below:

  1. BACKUP BACKUP BACKUP!
  2. Upload ‘includes’ directory (from directory corresponding to Your Zen Cart version) on Your server (via ftp, sftp or any other protocol).
  3. If You use MySQL >=5.0 copy and paste contents of sql_patch_for_mysql_5.x.sql into Store Admin Panel -> Tools -> Install SQL Patches. Execute the script.
  4. If You use MySQL <5.0 copy and paste contents of sql_patch.sql into Store Admin Panel -> Tools -> Install SQL Patches. Execute the script.
  5. Done.

If You use custom template add following line to proper tpl_main_page.php somewhere near end of the file:

<?php display_query_log(); ?>

After installation You’ll need to configure Query Log.

Configuration

Query Log adds three options to Admin Panel -> Configuration -> Logging:

  • Enable Database Query Log
  • Display queries to trusted users
  • Display queries to users with following email addresses (list of trusted users

Enable Database Query Log

When enabled all logged queries will be saved in database in query_log table.

Display queries to trusted users

Enables Basic Logger. It will display queries only to logged in users with email addresses listed in Display queries to users with following email addresses

Display queries to users with following email addresses

Comma separated list of emails.

Stay in touch

If You wish to be notified about new versions of Query Log, use cases, new screen casts or anything else related to Query Log type Your email address below hit ‘Subscribe’. You will only receive news regarding this contribution.


Continue Reading

Query Cache for Zen Cart released

2

Update: Query Cache V1.6 has been released – read here

Query Cache is free, in memory cache designed to work with Zen Cart. It can reduce number of queries sent to database by over 80% (see charts below). Thus, Query Cache  might greatly reduce query execution time and response time of most Zen Cart stores.

You might want to jump quickly to see Demo Stores. Compare number of queries on each store.

Performance Analysis

We’ve ran some tests on demo installment of Zen Cart 1.3.8a which contains just a few products, few categories, one customer and no orders. Still, Zen Cart generated over nine hundred queries (>900!) just to load first page of the demo store (You can check how many queries generates Your store by turning on ‘Display Page Parse Time’, read more). After that, Query Cache has been installed and it managed to reduce number of queries by half (from 900 to 199 queries approx.).

Other pages where also checked, including: category view page, search results page and ‘static’ (more or less) shipping information page. Results are presented on figures below:

Advantages of Query Cache

  • reduces number of queries sent to database by 80%
  • it’s very easy to install (jump to Installation instructions)
  • reduces page generation time, reduces load on database server.
  • works with all 1.3.x versions of Zen Cart

Disadvantages of Query Cache

As far as We can tell there is only one disadvantage: at this moment Query Cache can’t detect if database has been changed while php script is running. This means that if, for example, information about product is pulled from database, then product is updated, and retrieved again from database (all happening in one request) updated information might not be retrieved (in next request information will be updated).

Download

Here is package including Query Cache for ALL versions of Zen Cart 1.3.x:

Download Query Cache – latest version

Installation Instructions

First, download contribution here. Extract it with WinZip or something similar. Go to extracted directory. There are few directories named like ‘Zen-Cart 1.3.x’ where ‘x’ is minor version number of Zen Cart. To install this module:

  1. BACKUP BACKUP BACKUP!
  2. Upload ‘includes’ directory (from directory corresponding to Your Zen Cart version) on Your server (via ftp, sftp or any other protocol).
  3. Done.

Note: Query Cache v1.5 has feature that might slow down Your store if Your web server is very slow. In such case You can try to set QC_USE_PRODUCT_QUERY_DETECTION in includes/extra_configures/query_cache.php to FALSE.
This contribution is preconfigured to use Query Log _IF_ it’s available. If Query Log is not installed, Query Cache will still work without any problems (or at least it should;)

How to verify that Query Cache Works

Before installing Query Cache check how many queries Your store executes:

  • Enable ‘Display The Page Parse Time’ option in Store Admin in Configuration -> Logging.
  • Go to Your store, scroll down and see how many queries where executed.

Now, install Query Cache and visit the same page. Check query count, it should be much lower.

Screencast

Here is screencast showing how to install this contribution.

Demo Stores

Here are two Demo Stores:

Demo Store with Query Cache installed

Demo Store without Query Cache installed

Take a look at footer of each store. As You can see Query Cache greatly reduced number of executed queries.

Is it free? (Yes)

Yes, it is. You can use it on unlimited number of sites without any costs. You can redistribute it, change the source code (but leave us as original authors) etc. You can’t sell it or make any profit of it.

Stay in touch

We plan to release new version of Query Cache soon, with some new features that will further reduce number of executed queries and improve performance of Your store. Just type Your address here to be notified of new versions of Query Cache (You’ll receive only updates on Query Cache). Quick info: We hate spam, Your email will not be given to anyone.


Continue Reading

Social Stuff

Donate

If You like Query Cache, Query Log or Randomized Tests please make a $5 donation.

Search the blog