今天感觉mysql数据库写入时有时会失败,感觉是性能上有点问题,发现CPU很快就占满了,通过查找资料,有如下这么一段话

 I learned something surprising: In spite of the documentation, it is best to leave innodb_thread_concurrency at 0 (infinite concurrency). That way, InnoDB decides the best number of innodb_concurrecy_tickets to open for a given MySQL instance setup.

 Once you set innodb_thread_concurrency to 0, you can set innodb_read_io_threads and innodb_write_io_threads (both since MySQL 5.1.38) to the maximum value of 64. This should engage more cores.

可以看出通过设置通过innodb_thread_concurrency,innodb_read_io_threads innodb_write_io_threads 来设置,innodb_thread_concurrency这个参数设置为0时,表示不限制线程数。innodb_read_io_threads innodb_write_io_threads这两个参数默认值是4,如果CPU是2颗8核的,那么可以设置为innodb_read_io_threads=8,innodb_write_io_threads=8,当然如果是读比写多的话。可以把读的参数设置大点。

通过设置完成,可以发现还是不错的。

可以通过

cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l

cat /proc/cpuinfo | grep "cpu cores" | uniq

查看cpu的个数以及核数