Details and usage of thread pool in MariaDB, mariadbpool

Source: Internet
Author: User

Details and usage of thread pool in MariaDB, mariadbpool

What is Thread pool?

MySQL creates a thread for each connection to execute the statement. In this way, a new thread will be created for each new connection, which puts a lot of pressure on MySQL itself. Threadpool is a model that provides a thread proxy to execute each connection statement. MySQL maintains the total number of threads that may be accepted internally, reducing the stress on CPU switching and other aspects of too many threads.

Advantages of using Threadpool

1. The thread proxy model can be used to create a thread in advance and maintain it using the threadpool technology of the operating system when the number of connections is known to be controllable. This reduces a lot of overhead.

2. Use the thread management of the operating system as much as possible to minimize the thread management overhead. 3. Exploitation
Thread_pool_max_threads controls resource usage

Under what circumstances does the Thread Pool play a relatively small role:

1. Too high concurrency and long statement operations. For example, the total number of internal threadpools is 10, and 1000 requests are concurrently sent outside. Currently, all these 10 Internal Threads are competing for use, which is also a heavy overhead. Similarly, when threadpool is increased, innodb's internal concurrency will also be limited.

2. Burst connections. In this case, threadpool has a certain effect, but the effect is not obvious. To prevent a large number of connections. You can increase the value of thread_pool_min_threads and thread_pool_idle_timeout to maintain a large threadpool.

3. In a highly concurrent environment, simple queries may also slow down. Although select 1; such a query should be completed very quickly. However, under the threadpool, you also need to queue up and wait for the thread available from theadpool to be executed.

Usage:

Currently, threadpool is supported by MariaDB, Percona, and a charging function of MySQL. Enable configuration.

In my. cnf
Copy codeThe Code is as follows:
[Mysqld]
# Thread pool
Thread_handling = pool-of-threads


C # ThreadPool and Thread Multithreading

// Thread pool example
Using System;
Using System. Threading;
Public class Test
{
// Store the field of the value to be calculated
Static double number1 =-1;
Static double number2 =-1;
Public static void Main ()
{
// Obtain the maximum number of threads in the thread pool and the minimum number of Idle threads maintained
Int maxThreadNum, portThreadNum;
Int minThreadNum;
ThreadPool. GetMaxThreads (out maxThreadNum, out portThreadNum );
ThreadPool. GetMinThreads (out minThreadNum, out portThreadNum );
Console. WriteLine ("Maximum number of threads:", maxThreadNum );
Console. WriteLine ("minimum number of Idle threads:", minThreadNum );
// Function variable value
Int x = 15600;
// Start the first task: Calculate the power of x to the power of 8
Console. WriteLine ("start the first task: Calculate the power of 8. ", X );
ThreadPool. QueueUserWorkItem (new WaitCallback (TaskProc1), x );
// Start the second task: Calculate the 8th power of x
Console. WriteLine ("start the second task: Calculate the 8th power root. ", X );
ThreadPool. QueueUserWorkItem (new WaitCallback (TaskProc2), x );
// Wait until both values are calculated
While (number1 =-1 | number2 =-1 );
// Print the calculation result
Console. WriteLine ("y () =", x, number1 + number2 );
}
// Start the first task: Calculate the power of x to the power of 8
Static void TaskProc1 (object o)
{
Number1 = Math. Pow (Convert. ToDouble (o), 8 );
}
// Start the second task: Calculate the 8th power of x
Static void TaskProc2 (object o)
{
Number2 = Math. Pow (Convert. ToDouble (o), 1.0/8.0 );
}
}... Remaining full text>

How to Use the java thread pool newCachedThreadPool

ExecutorService threadPoll = Executors. newCachedThreadPool (); // create a thread pool
ThreadPoll.exe cute (new MyThread ());

This is enough. The jvm will determine how to obtain a thread and release it when it is used up...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.