cmd/soju: bump max number of opened files
The bouncer process may be dealing with many opened FDs. The default on Linux is 1024. To support bouncers with a lot of users, bump RLIMIT_NOFILE to the max as advised in [1]. [1]: http://0pointer.net/blog/file-descriptor-limits.html
This commit is contained in:
parent
179991036c
commit
4397cd7fc2
@ -50,6 +50,18 @@ func loadMOTD(srv *soju.Server, filename string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func bumpOpenedFileLimit() error {
|
||||
var rlimit syscall.Rlimit
|
||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
|
||||
return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err)
|
||||
}
|
||||
rlimit.Cur = rlimit.Max
|
||||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
|
||||
return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
var listen []string
|
||||
var configPath string
|
||||
@ -75,6 +87,10 @@ func main() {
|
||||
cfg.Listen = []string{":6697"}
|
||||
}
|
||||
|
||||
if err := bumpOpenedFileLimit(); err != nil {
|
||||
log.Printf("failed to bump max number of opened files: %v", err)
|
||||
}
|
||||
|
||||
db, err := soju.OpenDB(cfg.SQLDriver, cfg.SQLSource)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open database: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user