多进程与多线程(十五) ---MySQL

来源:互联网 发布:angular.js 2.0下载 编辑:程序博客网 时间:2024/05/17 15:56

3.2      多线程结构的数据库管理系统――MySQL

在MySQL中我们通过搜索CreateProcess等函数可以知晓,MySQL是多线程结构。

表1-Windows系统下涉及的函数

搜索的函数

涉及的文件

功能分析

_beginthreadex

extra\yassl\testsuite\Testsuite.cpp

测试相关,不涉及数据库服务器的结构

_beginthread

mysys\My_winthread.c

MySQL自定义了一个函数pthread_create(与Linux下的pthread_create函数同名),在windows系统下,pthread_create调用_beginthread实现线程创建。

调用序列如下:

os_thread_create->pthread_create->_beginthread

通过自定义的pthread_create函数创建的线程有:

1.         io_handler_thread

2.         srv_lock_timeout_and_monitor_thread

3.         srv_error_monitor_thread

4.         srv_master_thread

5.         trx_rollback_or_clean_all_without_sess

另外,MySQL定义了一个Threads类,通过此类的方法createThread调用windows下的CreateThread函数或linux下的pthread_create函数来创建线程。与此相关被创建的线程包括:

Database:数据库实例

PageWriter:刷出数据到外存

Scheduler:调度功能

SerialLog:日志

Server:socket监听进程

CreateThread

 

os_thread_create-> CreateThread

多进程与多线程(十五) - 那海蓝蓝 - 那海蓝蓝的博客
 

CreateProcess

 

 

表2-Linux系统下涉及的函数

搜索的函数

涉及的文件

功能分析

pthread_create

storage\innobase\io\os0thread.c

os_thread_create-> pthread_create

innobase_start_or_create_for_mysql-> os_thread_create

如果是linux系统,直接使用“pthread_create”函数,这在“my_pthread.h”通过宏对的pthread_create的限制可以看出,在“os0thread.c”中“os_thread_create”函数体可以看出。

linux等系统下使用的是NPTL中的“pthread_create”函数,而在windows下则模拟了此函数。

 

fork

libmysqld\stacktrace.c

 

storage\ndb\src\kernel\main.cpp

 

storage\ndb\src\cw\cpcd\process.cpp

 

Other files

同测试相关(tests目录下)或和pl脚本相关

从上述两表可以看出,MySQL和线程基本没有关系,只是局部的代码因操作系统平台不同使用了程序,而数据库服务器引擎的主要部分postmaster没有使用线程,而是通过internal_forkexec创建了诸多相关进程。可见其隶属于多进程结构。


原创粉丝点击