This is a creation in Article, where the information may have evolved or changed.
This is the system resource limit, usually single process can not exceed 1024, I use CGO to set, the code is as follows:
package main/*#include <stdio.h>#include <sys/time.h>#include <sys/resource.h>int rlimit_init() { printf("setting rlimit\n"); struct rlimit limit; if (getrlimit(RLIMIT_NOFILE, &limit) == -1) { printf("getrlimit error\n"); return 1; } limit.rlim_cur = limit.rlim_max = 50000; if (setrlimit(RLIMIT_NOFILE, &limit) == -1) { printf("setrlimit error\n"); return 1; } printf("set limit ok\n"); return 0;}*/import "C"func main() { C.rlimit_init()}
Or use the Syscall package
var rlim syscall.Rlimiterr := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)if err != nil { fmt.Println("get rlimit error: " + err.Error()) os.Exit(1)}rlim.Cur = 50000rlim.Max = 50000err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)if err != nil { fmt.Println("set rlimit error: " + err.Error()) os.Exit(1)}
After compiling with go build, you need to run with the root permission.