日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql打开的文件描述符限制_linux fopen个数限制的问题(文件描述符限制)

發布時間:2025/3/19 数据库 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql打开的文件描述符限制_linux fopen个数限制的问题(文件描述符限制) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題出現的情況大概是這樣的:我有一個多線程程序,每個線程是要fopen一個文件。當打開到第900+個的時候,程序突然異常退出,原因是fopen得到的為空,及不能再打開文件了。這是我查看了一下進程最大打開文件描述符數:ulimit -Sn ,值是1024。ulimit -Hn,值是4096。我就懷疑是這個1024限制了線程的打開文件數。接下來我就參照以下文檔改這個值。

ile Descriptor Requirements (Linux Systems)

To ensure good server performance, the total number of client connections, database files, and log files must not exceed the maximum file descriptor limit on the operating system (ulimit?-n). By default, the directory server allows an unlimited number of connections but is restricted by the file descriptor limit on the operating system. Linux systems limit the number of file descriptors that any one process may open to 1024 per process. (This condition is not a problem on Solaris machines, x86, x64, or SPARC).

After the directory server has exceeded the file descriptor limit of 1024 per process, any new process and worker threads will be blocked. For example, if the directory server attempts to open a Oracle??Berkeley JE database file when the operating system has exceeded the file descriptor limit, the directory server will no longer be able to open a connection that can lead to a corrupted database exception. Likewise, if you have a directory server that exceeds the file descriptor limit set by the operating system, the directory server can become unresponsive as the LDAP connection handler consumes all of the CPU's processing in attempting to open a new connection.

To fix this condition, set the maximum file descriptor limit per process on Linux machines.

To Increase the File Descriptor Limit (Linux)

Display the current hard limit of your machine.

The hard limit is the maximum server limit that can be set without tuning the kernel parameters in?proc?file system. $ ulimit -aH

core file size (blocks) unlimited

data seg size (kbytes) unlimited

file size (blocks) unlimited

max locked memory (kbytes) unlimited

max memory size (kbytes) unlimited

open files 1024

pipe size (512 bytes) 8

stack size (kbytes) unlimited

cpu time (seconds) unlimited

max user processes 4094

virtual memory (kbytes) unlimited

Edit the?/etc/security/limits.conf?and add the lines: * soft nofile 1000000

* hard nofile 1000000

Edit the?/etc/pam.d/login?by adding the line: session required /lib/security/pam_limits.so

Use the system file limit to increase the file descriptor limit to 65535.

The system file limit is set in?/proc/sys/fs/file-max?. echo 1000000> /proc/sys/fs/file-max

Use the?ulimit?command to set the file descriptor limit to the hard limit specified in/etc/security/limits.conf. ulimit -n 1000000

Restart your system.

reboot

再次查看unlimit -Sn ,值為1000000,unlimit -Hn,值為1000000.

再次跑我的程序的時候,順利突破1000的大關。這會兒已經跑到2000+了也沒出問題。

參考https://www.cnblogs.com/qq78292959/archive/2012/03/07/2383337.html。

參考https://blog.csdn.net/chinaclock/article/details/48346117?utm_source=blogkpcl8。

感謝這兩位博主的無私奉獻!

總結

以上是生活随笔為你收集整理的mysql打开的文件描述符限制_linux fopen个数限制的问题(文件描述符限制)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。