One more approach is to gather statistics in the database. Since you often don't care about the really fast queries, this can be quite useful. With mysql 5.1 you can do this:
set-variable = long_query_time=0.5
slow_query_log_file = /var/mysql-data/databases/log-slow-queries.log
slow_query_log = ON
Note that the long query time is in seconds and since 5.1 can take values less than one second. There is another flag which logs output which uses non-indexed queries.
Then I recommend this tool: mysqlsla
It will analyse your logs and give you aggregated summaries which are really nice.
Ari Maniatis
On 29/12/09 7:16 PM, Andrus Adamchik wrote:
> We started on an implementation of a flexible statistics gathering
> engine some time ago:
>
> https://issues.apache.org/jira/browse/CAY-1173
>
> I hope this gets finished in Cayenne 3.1. Until then you have 2 places
> where you may try intercepting query events:
>
> * DataSource. Since DataSource is an interface, you can implement your
> own wrapper around the current DataSource that you are using, set up via
> a custom DataSourceFactory. Then you'd have to also decorate Connection
> and PreparedStatement. PreparedStatement wrapper would gather needed
> statistics.
>
> * Log4J. You can create an appender that analyzes Cayenne QueryLogger
> log events gathering needed stats.
>
> Andrus
>
>
> On Dec 29, 2009, at 10:03 AM, Hans Pikkemaat wrote:
>> Hi,
>>
>> I'm doing some performance tests and want to see when the query is
>> actually run.
>> I'm running some test queries with different cache settings to see
>> what happens
>> performance and memory wise. For this reason I need to know when an
>> actual
>> sql statement is being executed at the database. So my question is:
>>
>> Is there a way (2.0.4) to get a notification or callback when a query
>> (or more generic: sql statement) is executed?
>>
>> I'm already using the log4j so I do see when the query runs but I need
>> a callback to be
>> able to store statistics about a query execution. Preferably including
>> result counts and execution timing.
>>
>> I saw the explanation about the DataContextDelegate but this one is
>> called even when a query is in the cache.
>>
>> tx
>>
>> Hans
>
----------------------------> Aristedes Maniatis GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
This archive was generated by hypermail 2.0.0 : Tue Dec 29 2009 - 04:00:46 EST