One day, two people who didn’t understand the mysql kernel wanted to understand the mysql kernel code. Instead of debugging the code and looking for information, the two people That’s where you think. Because I don’t understand the kernel, I verify it while thinking about it.
The mysql code used is 5.1.7, and the debugging environment is vs2003 under the windows platform.
Bingxi: "Alex, what do you think the startup process of mysql will be like? Let's take bank as an example." Alex: "Well, bingxi. The bank is open this morning. The environment will be prepared first, and then the door will be opened to welcome guests. The same is true for mysql. There will be a han
dle_connections_socketsfunction in Mysql. This function is like a dialing machine. Each user comes to A number will be taken, and then the business will be processed. "
pthread_handler_t handle_connections_sockets(void *arg attribute((unused))) { …… while (!abort_loop) { select((int) max_used_connection,&readFDs,0,0,0) < 0) //有连接了则往下来执行,否则一直等待 …… accept(sock, my_reinterpret_cast(struct sockaddr *) (&cAddr),&length) //接受请求 …… create_new_thread(thd); } //abort_loop=1,则执行到这里进行推出。今天业务不处理了 }
queue, and get the service from the designated window according to the number calling machine. The former scenario is suitable for situations where the request volume is large and the response speed is particularly fast, but there will also be distribution problems. There is a limit, the so-called maximum number of connections. This situation is common in the Internet industry. Correspondingly, we can see that the load variation range of the machine is particularly large. Similarly, this is also one of its drawbacks, assuming that each business is complex (consumes resources). SQL statements), the machine will not be able to support it if processed at the same time. In this case, the second method is better. This situation belongs to a transactional scenario. "Alex: "Well, yes, Mysql chooses the former. , Oracle provides two methods to choose from. Let’s continue to look at the following code. If we configure the thread
cache, and there is an available cache, wake up the thread, otherwise create a new thread.”
static void create_new_thread(THD *thd) { if (cached_thread_count > wake_thread) { start_cached_thread(thd); } else { if ((error=pthread_create(&thd->real_id,&connection_attrib, handle_one_connection, (void*) thd))) } }
The above is the detailed content of Parse the startup process of mysql. For more information, please follow other related articles on the PHP Chinese website!