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

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 :

Percona 5.5 has improvements in stabilize IO and flushing activity. The related variables are talked about here:

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.