Why can 'query end' thread state take long time?

Hi,
Threads can leave in ‘query end’ state for seconds.

Percona 5.5.16
Centos 6

That could happen when the system stalls. The cause could be a checkpoint flushing storm, or contention on query cache, or other reasons.

For innodb flushing storm, you can read about it from these blog posts :
http://www.mysqlperformanceblog.com/2011/04/04/innodb-flushing-theory-and-solutions/
http://www.mysqlperformanceblog.com/2011/09/18/disaster-mysql-5-5-flushing/

Percona 5.5 has improvements in stabilize IO and flushing activity. The related variables are talked about here:
http://www.percona.com/doc/percona-server/5.5/scalability/innodb_io_55.html

For query cache, you may check global status Qcache_% to see the usage info, and use Qcache_hits / (Com_select + Qcache_hits) x 100 to check efficiency. For most write heavy workload, it is better to disable query cache for improved overall performance.