@@ 14,11 14,17 @@ import (
"api/middlewares"
"log"
"os"
+ "syscall"
"github.com/gin-gonic/gin"
)
func main() {
+ err := setUlimits()
+ if err != nil {
+ log.Fatal("failed to set Ulimits")
+ }
+
dbConnectionString := os.Getenv("GORM_DB_STRING")
db.Connect(dbConnectionString)
@@ 57,3 63,13 @@ func createRouter() *gin.Engine {
}
return router
}
+
+// Set NOFILE limit to max, to allow more concurrent websocket connections
+func setUlimits() error {
+ var rlimit syscall.Rlimit
+ if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
+ return err
+ }
+ rlimit.Cur = rlimit.Max
+ return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
+}