Browse Source

Added configration for maxfd and automatically use the numer of cpus for GOMAXPROCS per default.

pull/3/head
Simon Eisenmann 12 years ago
parent
commit
55e22afe32
  1. 4
      debian/changelog
  2. 1
      server.conf.in
  3. 2
      spreed-speakfreely-server
  4. 37
      src/app/spreed-speakfreely-server/main.go

4
debian/changelog vendored

@ -2,8 +2,10 @@ spreed-speakfreely-server (0.15.1) precise; urgency=low @@ -2,8 +2,10 @@ spreed-speakfreely-server (0.15.1) precise; urgency=low
* Changed Makefile to allow tarball and release builds with
local third party sources in ./vendor too.
* Added configration for maxfd and automatically use the
numer of cpus for GOMAXPROCS per default.
-- Simon Eisenmann <simon@struktur.de> Tue, 04 Mar 2014 11:10:31 +0100
-- Simon Eisenmann <longsleep@redemption.intranet.struktur.de> Tue, 04 Mar 2014 11:45:29 +0100
spreed-speakfreely-server (0.15.0) precise; urgency=low

1
server.conf.in

@ -6,6 +6,7 @@ listen = 127.0.0.1:8080 @@ -6,6 +6,7 @@ listen = 127.0.0.1:8080
#readtimeout = 10
#writetimeout = 10
#basePath = /some/sub/path/ # Set this when running behind a web server under a sub path.
#maxfd = 32768 # Try to set max open files limit on start (works only when run as root).
[app]
#title = Spreed Speak Freely

2
spreed-speakfreely-server

@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
#!/bin/bash
GOMAXPROCS=8 exec ./bin/spreed-speakfreely-server $*
exec ./bin/spreed-speakfreely-server $*

37
src/app/spreed-speakfreely-server/main.go

@ -32,15 +32,12 @@ import ( @@ -32,15 +32,12 @@ import (
"net/http"
"os"
"path"
goruntime "runtime"
"strings"
"syscall"
"time"
)
const (
RLIMIT_NO_FILE = 32768
)
var version = "unreleased"
var defaultConfig = "./server.conf"
@ -256,19 +253,33 @@ func runner(runtime phoenix.Runtime) error { @@ -256,19 +253,33 @@ func runner(runtime phoenix.Runtime) error {
// Create our hub instance.
hub := NewHub(runtimeVersion, config, sessionSecret, turnSecret)
// Try to increase number of file open files. This only works as root.
// Set number of go routines if it is 1
if goruntime.GOMAXPROCS(0) == 1 {
nCPU := goruntime.NumCPU()
goruntime.GOMAXPROCS(nCPU)
log.Printf("Using the number of CPU's (%d) as GOMAXPROCS\n", nCPU)
}
// Get current number of max open files.
var rLimit syscall.Rlimit
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Println("Error getting rlimit numer of files", err)
}
rLimit.Max = RLIMIT_NO_FILE
rLimit.Cur = RLIMIT_NO_FILE
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Println("Error setting rlimit", err)
log.Println("Error getting max numer of open files", err)
} else {
log.Printf("Set rlimit successfully to %d\n", RLIMIT_NO_FILE)
log.Printf("Max open files are %d\n", rLimit.Max)
}
// Try to increase number of file open files. This only works as root.
maxfd, err := runtime.GetInt("http", "maxfd")
if err == nil {
rLimit.Max = uint64(maxfd)
rLimit.Cur = uint64(maxfd)
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Println("Error setting max open files", err)
} else {
log.Printf("Set max open files successfully to %d\n", uint64(maxfd))
}
}
// Create router.

Loading…
Cancel
Save