MySQL之thread cache_MySQL
bitsCN.com
最近突然对MySQL的连接非常感兴趣,从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 there. Requests for threads are satisfied by reusing threads taken from the cache if possible, and only when the cache is empty is a new thread created. This variable can be increased to improve performance if you have a lot of new connections. Normally, this does not provide a notable performance improvement if you have a good thread implementation. However, if your server sees hundreds of connections per second you should normally set thread_cache_size high enough so that most new connections use cached threads. By examining the difference between the Connections and Threads_created status variables, you can see how efficient the thread cache is. For details, see Section 5.1.6, “Server Status Variables”.
众所周知,mysql建立连接非常消耗资源,所以就有了thread_cache,当已有连接不再使用之后,mysql server不是直接断开连接,而是将已有连接转入到thread_cache中,以便下次在有create thread的需求时,可以在cache中复用,提高性能,降低资源消耗。
当然,如果已经有了中间件或者其他的连接池管理,那么这个参数就没有那么重要了,但是如果没有其他的连接池管理,那么优化这个参数还是可以得到不错的回报的。
bitsCN.com
핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











C 언어에서 static 키워드의 역할과 사용법에 대한 심층 분석 C 언어에서 static은 함수, 변수 및 데이터 유형을 정의하는 데 사용할 수 있는 매우 중요한 키워드입니다. static 키워드를 사용하면 객체의 링크 속성, 범위, 생명주기가 변경될 수 있습니다. C 언어에서 static 키워드의 역할과 사용법을 자세히 분석해 보겠습니다. 정적 변수 및 함수: 함수 내에서 static 키워드를 사용하여 정의된 변수를 전역 수명 주기를 갖는 정적 변수라고 합니다.

Java에서 멀티스레딩을 구현하는 방법에는 두 가지가 있습니다. 하나는 Thread 클래스를 상속하는 것이고, 다른 하나는 Runnable 인터페이스를 구현하는 것입니다. Thread 클래스는 java.lang 패키지에 정의되어 있습니다. 클래스가 Thread 클래스를 상속하고 이 클래스의 run() 메서드를 재정의하는 한 다중 스레드 작업을 구현할 수 있습니다. 그러나 클래스는 하나의 상위 클래스만 상속할 수 있으며 이는 이 메서드의 제한 사항입니다. 예를 살펴보겠습니다: packageorg.thread.demo;classMyThreadextendsThread{privateStringname;publicMyThread(Stringname){super();this

제목: C언어에서는 go가 키워드인가요? 상세 분석 C 언어에서 "go"는 키워드가 아닙니다. C 언어의 키워드는 C 표준에 의해 지정되며 특정 문법 구조나 기능을 나타내는 데 사용됩니다. 이는 컴파일러에서 특별한 의미를 가지며 식별자나 변수 이름으로 사용할 수 없습니다. 예를 들어, 키워드 "int"는 정수 데이터 유형을 나타내고 "if"는 조건문을 나타내는 식입니다. "go"가 C 언어의 키워드인지 확인하려면 간단한 프로그램을 작성하여 테스트할 수 있습니다. 예는 다음과 같습니다: #inc

PHP에서 var 키워드의 역할과 예 PHP에서는 var 키워드를 사용하여 변수를 선언합니다. 이전 PHP 버전에서는 var 키워드를 사용하는 것이 멤버 변수를 선언하는 관용적인 방법이었지만 더 이상 사용이 권장되지 않습니다. 그러나 어떤 경우에는 var 키워드가 계속 사용됩니다. var 키워드는 주로 지역 변수를 선언하는 데 사용되며 해당 변수는 자동으로 지역 범위로 표시됩니다. 즉, 변수는 현재 코드 블록 내에서만 볼 수 있으며 다른 함수나 코드 블록에서는 액세스할 수 없습니다. var 사용

C 언어에는 32개의 키워드가 있습니다. 키워드의 기능에 따라 데이터 유형 키워드, 제어문 키워드, 저장 유형 키워드 및 기타 키워드의 네 가지 범주로 나눌 수 있습니다. char, double, float, int 등을 포함한 12개의 데이터 유형 키워드가 있습니다. for, break, if, else, do 등을 포함한 12개의 제어문 키워드가 있습니다. auto, static, extern 등 const, sizeof 등을 포함한 4개의 다른 키워드가 있습니다.

Java의 Thread.start() 함수를 사용하여 새 스레드를 시작합니다. Java에서는 멀티스레딩을 사용하여 여러 작업을 동시에 실행할 수 있습니다. Java는 스레드를 생성하고 관리하기 위한 Thread 클래스를 제공합니다. Thread 클래스의 start() 함수는 새 스레드를 시작하고 스레드의 run() 메서드에 있는 코드를 실행하는 데 사용됩니다. 코드 예: publicclassMyThreadextendsThread{@Overr

Go 언어에서 while은 키워드가 아닙니다. "for {sum++ if sum>10{break}else{...}}"와 같이 for 문과 break를 함께 사용하면 while 루프의 효과를 얻을 수 있습니다. go 언어에는 break, default, func, select, case, defer, go, map, else, goto, for, if, var 등과 같은 25개의 키워드가 있습니다.

자바에서는 쓰레드에 있어서 쓰레드(Thread)가 필수적이다. 스레드는 프로세스보다 더 가벼운 예약 실행자입니다. 스레드를 사용하는 이유는 무엇입니까? 스레드를 사용하면 운영 체제 프로세스에서 리소스 할당과 실행 일정을 분리할 수 있습니다. 각 스레드는 프로세스 리소스(메모리 주소, 파일 I/O 등)를 공유할 수 있을 뿐만 아니라 독립적으로 예약할 수도 있습니다(스레드는 CPU 예약의 기본 단위입니다). 참고 1. Thread는 Thread를 만드는 데 가장 중요한 클래스이며, 단어 자체도 Thread를 나타냅니다. 2. Thread 클래스는 Runnable 인터페이스를 구현합니다. 인스턴스 publicclassThreadDemoextendsThread{publicvoidrun(){for(inti=0
