5 changed files with 68 additions and 31 deletions
@ -0,0 +1,24 @@ |
|||||||
|
// +build !freebsd
|
||||||
|
|
||||||
|
package chat |
||||||
|
|
||||||
|
import ( |
||||||
|
"syscall" |
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus" |
||||||
|
) |
||||||
|
|
||||||
|
func setSystemConcurrentConnectionLimit(limit int64) { |
||||||
|
var rLimit syscall.Rlimit |
||||||
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
|
||||||
|
originalLimit := rLimit.Cur |
||||||
|
rLimit.Cur = uint64(limit) |
||||||
|
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
|
||||||
|
log.Traceln("Max process connection count changed from system limit of", originalLimit, "to", limit) |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
// +build freebsd
|
||||||
|
|
||||||
|
package chat |
||||||
|
|
||||||
|
import ( |
||||||
|
"syscall" |
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus" |
||||||
|
) |
||||||
|
|
||||||
|
func setSystemConcurrentConnectionLimit(limit int64) { |
||||||
|
var rLimit syscall.Rlimit |
||||||
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
|
||||||
|
originalLimit := rLimit.Cur |
||||||
|
rLimit.Cur = int64(limit) |
||||||
|
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
|
||||||
|
log.Traceln("Max process connection count changed from system limit of", originalLimit, "to", limit) |
||||||
|
} |
@ -1,29 +1,15 @@ |
|||||||
package chat |
package chat |
||||||
|
|
||||||
import ( |
import "syscall" |
||||||
"syscall" |
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus" |
func getMaximumConcurrentConnectionLimit() int64 { |
||||||
) |
|
||||||
|
|
||||||
// Set the soft file handler limit as 70% of
|
|
||||||
// the max as the client connection limit.
|
|
||||||
func handleMaxConnectionCount() uint { |
|
||||||
var rLimit syscall.Rlimit |
var rLimit syscall.Rlimit |
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
||||||
panic(err) |
panic(err) |
||||||
} |
} |
||||||
|
|
||||||
originalLimit := rLimit.Cur |
// Return the limit to 70% of max so the machine doesn't die even if it's maxed out for some reason.
|
||||||
// Set the limit to 70% of max so the machine doesn't die even if it's maxed out for some reason.
|
proposedLimit := int64(float32(rLimit.Max) * 0.7) |
||||||
proposedLimit := int(float32(rLimit.Max) * 0.7) |
|
||||||
|
|
||||||
rLimit.Cur = uint64(proposedLimit) |
|
||||||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { |
|
||||||
panic(err) |
|
||||||
} |
|
||||||
|
|
||||||
log.Traceln("Max process connection count increased from", originalLimit, "to", proposedLimit) |
|
||||||
|
|
||||||
return uint(float32(rLimit.Cur)) |
return proposedLimit |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue