包含标签:thread cache 的文章
  • MySQL之thread cache

    从status根据thread关键字可以查出如下是个状态 show global status like 'thread%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 57 | | Threads_connected | 1268 | | Threads_created | 31715 | | Threads_running | 1 | +-------------------+-------+ Thread_cached:The number of threads in the thread cache Thread_connected:The number of currently open connections. Thread_created:The number of threads created to handle connections. Thread_running:The number of threads that are not sleeping. 以上是这4个状态的含义,thread_connected等于show processlist,thread_running代表真正在运行的(等于1一般就是这个show status命令本身),thread_cached代表mysql管理的线程池中还有多少可以被复用的资源,thread_created代表新创建的thread(根据官方文档,如果thread_created增大迅速,需要适当调高thread_cache_size)。 我们先来实际看下这4个状态之间的直观关系。 从上面这个图,我们可以总结出来一个公式:running和其他三个状态关系不大,但肯定不会超过thread_connected (new_con-old_con)=create+(old_cache-new_cache) 从上面公式可以看出,如果create等于0,那么thread_connected减少的和thread_cached增加的相等,thread_connected增加的和thread_cached减少的相等。(其实这也就是thread_cached存在的意义,资源可以复用)   我们来看眼影响thread_cached的参数thread_cache_size How many threads the server should cache for reuse. When a client disconnects, the client's threads are put in the cache if there are fewer than thread_cache_size threads ……

    SE_Gao 2024-02-28
    16 0 0