Percona 8.0 스레드 풀 소스 분석

Percona 8.0 ThreadPool이의 기본 기능 만 여기에만 초기화 프로세스의 스레드 플러그 및 호출 프로세스를하는 방식 호출이 변경되지, 거기에 많은 변화가 없습니다.

자체가 참조 할 수 있습니다 스레드 풀 논리 :

MariaDB · 소스 코드 분석 · 스레드 풀

Percona 5.7 스레드 풀 소스 코드 분석

스레드 플러그인 초기화

스레드 풀은이 기능을 설정 매개 변수가 --thread 처리 지정하려면 기본적으로 꺼져 = 풀의 쓰레드는 인스턴스를 시작해야 할 때. Connection_handler_manager가 고정 부재 변수 thread_handling, 싱글 클래스이며, 상기 코드에 대응이 매개 변수는, Connection_handler_manager :: thread_handling이다. Connection_handler_manager 코드는 인스턴스가 시작되면이 특별한 스레드 수에들을 때, 추상적 연결 모델 인 지정 여부 TCP 포트와 유닉스 소켓, mysqld_main에 구현 된 코드의이 부분에 새로운 연결 요청 -> Connection_acceptor-> connection_event_loop () 언제 해당 Connection_handler의 add_connection 객체 ()의 가상 메소드 Connection_handler_manager 연결 프로세스가 호 연결 요청 스레드 풀 및 스레드 풀 활성화 때문에 여기 스레드 당 연결 모델이 다른 코드 경로를 입력하기 전에, Connection_handler_manager :: 핸들러는 Thread_pool_connection_handler 개체, 스레드 당 연결 모델 Per_thread_connection_handler 개체를 회원입니다. Connection_handler_manager이 :: 따라 Connection_handler_manager에 초기화하기 함수가 Connection_handler_manager :: 핸들러입니다 결정 : 어떤 클래스 생성자 결정 오브젝트를 thread_handling.

Connection_handler_manager::init()
{
  switch (Connection_handler_manager::thread_handling)
  {
  case SCHEDULER_ONE_THREAD_PER_CONNECTION:
    connection_handler= new (std::nothrow) Per_thread_connection_handler();
    break;
  case SCHEDULER_NO_THREADS:
    connection_handler= new (std::nothrow) One_thread_connection_handler();
    break;
  case SCHEDULER_THREAD_POOL:
    connection_handler= new (std::nothrow) Thread_pool_connection_handler();
    break;
  default:
    DBUG_ASSERT(false);
  }
}
mysqld_main
 ->init_server_components
  ->plugin_register_dynamic_and_init_all
   ->plugin_init_initialize_and_reap
    ->plugin_initialize
     ->threadpool_plugin_init
	    tp_init  # 初始化threadpool
	    my_connection_handler_set  # 设置connection_handler
		 Plugin_connection_handler *conn_handler = new (std::nothrow) Plugin_connection_handler(chf);
		 Connection_handler_manager::get_instance()->load_connection_handler(conn_handler);

상기 코어 입구 tp_init 스레드 초기화 배열 thread_group_t 초기화.

my_connection_handler_set 연결 모드 설정 처리.

호출 프로세스의 스레드

mysqld_main
 ->connection_event_loop
  ->Connection_handler_manager::process_new_connection
   ->add_connection

어떤 add_connection 입구 스레드의 핵심이며, 주요 내용은 다음과 같습니다 :

대기열 그룹 삽입 연결, thread_group에 할당 된 연결을 만듭니다.

- 일어나 또는 그룹이 활성 작업자 스레드가 아닌 경우, 작업자 스레드를 만들 수 있습니다.

추천

출처www.cnblogs.com/jmliao/p/12627860.html