Average Queries per certain seconds

Developed In: SQL — Contributed by: Mohammad Lahlouh

The MySQL 5.1 offers new GLOBAL_STATUS information schema tables. These can be used to report certain performance metrics, such as the number of queries processed per certain seconds, NOT overall avg queries per second, Its good to know how much qps in peak hours.


Mohammad Lahlouh
SQL
  1. delimiter //
  2.  
  3. DROP PROCEDURE IF EXISTS qps//
  4.  
  5. CREATE PROCEDURE `qps`(timer int)
  6. BEGIN
  7.  
  8. -- Last Updated 01 oct 2009
  9. -- Mohammad Lahlouh
  10. -- mohammadlahlouh.blogspot.com
  11.  
  12. DROP TEMPORARY TABLE IF EXISTS tmp_status;
  13. CREATE TEMPORARY TABLE tmp_status (Queries int, Uptime int);
  14.  
  15.  
  16. -- Queries vs. Questions to support before and after MySQL 5.1.31
  17.  
  18. INSERT INTO tmp_status
  19. SELECT MAX( IF(variable_name IN ('Queries','Questions') , CAST(variable_value AS UNSIGNED) , 0 )) AS Queries,
  20. MAX( IF(variable_name='Uptime' , CAST(variable_value AS UNSIGNED) , 0 )) AS Uptime
  21. FROM information_schema.GLOBAL_STATUS
  22. WHERE variable_name IN ('Queries', 'Uptime', 'Questions');
  23.  
  24. SELECT sleep(timer) INTO @x;
  25.  
  26. INSERT INTO tmp_status
  27. SELECT MAX( IF(variable_name IN ('Queries','Questions') , CAST(variable_value AS UNSIGNED) , 0 )) AS Queries,
  28. MAX( IF(variable_name='Uptime' , CAST(variable_value AS UNSIGNED) , 0 )) AS Uptime
  29. FROM information_schema.GLOBAL_STATUS
  30. WHERE variable_name IN ('Queries', 'Uptime', 'Questions');
  31.  
  32. SELECT (MAX(Queries) - MIN(Queries)) / (MAX(Uptime) - MIN(Uptime)) AS AVG_QPS FROM tmp_status;
  33.  
  34. END//
  35.  
  36. delimiter ;
  37.  

Current Tags

You must be logged in to tag this tool

No Comments yet

Votes

  • Rated 5.00 out of 5
Rated 5.00 out of 5 with 1 votes cast.
You must be logged in to vote.

Watches

1 members are watching this tool
You must be logged in to track this tool.

Provide Feedback

Please note:
HTML will be purified, but we allow for a number of HTML tags so that you have the flexibility to decorate your comment text to some extent. The comments allow the following HTML tags:

strong, b, em, blockquote, a, code, pre

To put code into your comment, simply encapsulate your code with
[code language="XXX"][/code], where XXX is any common language, for instance "PHP", "SQL", "C", etc.



You must be logged in to comment