How to solve the problem of too many open files in Linux

How to solve the problem of too many open files in Linux

The cause is that the process opens a number of files and communication links that exceed the system limit at a certain moment. You can use the command ulimit -a to view the maximum number of handles currently set by the system.

core file size (blocks, -c) 0

data seg size (kbytes, -d) unlimited

scheduling priority (-e) 0

file size (blocks, -f) unlimited

pending signals (-i) 31767

max locked memory (kbytes, -l) 64

max memory size (kbytes, -m) unlimited

open files (-n) 1024

pipe size (512 bytes, -p) 8

POSIX message queues (bytes, -q) 819200

real-time priority (-r) 0

stack size (kbytes, -s) 8192

cpu time (seconds, -t) unlimited

max user processes (-u) 31767

virtual memory (kbytes, -v) unlimited

file locks (-x) unlimited

As you can see, the configuration of open files is 1024. You can increase the open files by running the following command

ulimit -n 65535

This modification method can temporarily increase the number of open files to 65535, but this configuration will become invalid after the system restarts.

Another way is to modify the system configuration file. Taking Ubuntu as an example, the default configuration file is

/etc/security/limits.conf

Add this configuration file

* soft nofile 65535 * hard nofile 6553

If you want to view the number of handles currently opened by a process, you can use the following command:

lsof -p process ID | wc -l

In addition, if you use supervisor to host and start the project, you will encounter the problem that this configuration cannot take effect. The reason is that supervisor will configure the number of open handles to be 1024 by default.

If you want to view the maximum open files of a process, you can view it through the limits corresponding to the process number of this process.

cat /proc/process ID/limits

One of the lines is:

Max open files 10241024bytes

The default value of the supervisor-hosted program is 1024, which is the maximum number of supervisor configurations. At this time, you need to manually modify the supervisor configuration file. The modification method is as follows. Taking the Ubuntu system as an example, find the supervisor configuration file supervisord.conf

In the [supervisord] option, add the minfds option configuration

[supervisord]minfds=65535 ; min. avail startup file descriptors; default 1024

After configuration, you need to restart supervisor (taking systemctl as an example)

systemctl restart supervisor

It will take effect

In passing:

cat /proc/process number/limits

Check the number of open files for the corresponding process

Max open files 6553565535 bytes

The above is the detailed content on how to solve the problem of Too many open files under Linux. For more information on solving the problem of Too many open files under Linux, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • A brief discussion on Linux virtual memory
  • Analysis of C++ compilation and linking under Linux
  • Implementation of Linux installation of Pytorch1.8GPU (CUDA11.1)
  • Tutorial on deploying springboot package in linux environment using docker
  • An example of using R language to draw pictures in Linux command line
  • A detailed introduction to the Linux directory structure
  • Linux commonly used commands performance commands
  • Linux View File System Type Example Method
  • Solution to pip upgrade error in Linux system

<<:  It is not recommended to copy the content in Word directly to the editor on the website.

>>:  Input file custom button beautification (demo)

Recommend

A brief discussion on MySQL index optimization analysis

Why are the SQL queries you write slow? Why do th...

Simple setup of VMware ESXi6.7 (with pictures and text)

1. Introduction to VMware vSphere VMware vSphere ...

How to deploy k8s in docker

K8s k8s is a cluster. There are multiple Namespac...

Quickly solve the problem of slow Tomcat startup, super simple

Today I helped a classmate solve a problem - Tomc...

MySQL database connection exception summary (worth collecting)

I found a strange problem when deploying the proj...

How to implement communication between Docker containers

Scenario: A laradock development environment (php...

Detailed explanation of mysql transaction management operations

This article describes the MySQL transaction mana...

WeChat applet selects the image control

This article example shares the specific code for...

Linux kernel device driver advanced character device driver notes

/****************** * Advanced character device d...

Native JS to achieve drag photo wall

This article shares with you a draggable photo wa...

Detailed explanation of mkdir command in Linux learning

Table of contents Preface 1. Basic knowledge of f...

Detailed explanation of for loop and double for loop in JavaScript

for loop The for loop loops through the elements ...

Web page custom selection box Select

Everyone may be familiar with the select drop-dow...