0

I have a very simple go server:

package main

import(
  "net/http"
  "fmt"
  "log"
)

func test(w http.ResponseWriter, r *http.Request){
  fmt.Println("No bid")
  http.Error(w, "NoBid", 204)
}

func main() {
  http.HandleFunc("/test/bid", test)
  http.ListenAndServe(":8080", nil)
  log.Println("Done serving")
}

I then run the apache benchmark tool:

ab -c 50 -n 50000 -p post.txt http://127.0.0.1:8080/test/bid

The Server runs and responds to about 15000 requests and then times out. I was wondering why this happens and if there is something I can do about this.

5
  • try running your executable in the following way: nohup ./[name] Commented Dec 12, 2013 at 23:19
  • 1
    Did you try and close the Request.Body? Commented Dec 12, 2013 at 23:21
  • What error are you getting (if any?). Chances are you are starved of open sockets on your operating system. I'd also recommend using wrk (github.com/wg/wrk) or weighttp (github.com/lighttpd/weighttp) instead of Apache Bench. Commented Dec 12, 2013 at 23:22
  • Thank you for the feedback, I could not get nohup or r.Body.Close to alleviate my problem. I will check out the other benchmarking tools and see if I can find anything. Commented Dec 12, 2013 at 23:39
  • I started to use wrk and I think it is better for what I am doing, thank you much Commented Dec 13, 2013 at 0:08

2 Answers 2

3

If you running in Linux, Maybe too many open files, so it can't create connection, You need change system config to support more connections.

For example,

edit /etc/security/limits.conf add

*    soft    nofile 100000
*    soft    nofile 100000

To open more file.

edit /etc/sysctl.conf

# use more port
net.ipv4.ip_local_port_range = 1024 65000
# keep alive timeout
net.ipv4.tcp_keepalive_time = 300
# allow reuse
net.ipv4.tcp_tw_reuse = 1
# quick recovery
net.ipv4.tcp_tw_recycle = 1
Sign up to request clarification or add additional context in comments.

Comments

2

I tried to replicate your problem on my linux amd64 laptop with no success - it worked fine even with

ab -c 200 -n 500000 -p post.txt http://127.0.0.1:8080/test/bid

There were about 28,000 sockets open though which may be bumping a limit on your system.

A more real world test might be to turn keepalives on which maxes out at 400 sockets

ab -k -c 200 -n 500000 -p post.txt http://127.0.0.1:8080/test/bid

The result for this was

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /test/bid
Document Length:        6 bytes

Concurrency Level:      200
Time taken for tests:   33.807 seconds
Complete requests:      500000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    500000
Total transferred:      77000000 bytes
Total body sent:        221500000
HTML transferred:       3000000 bytes
Requests per second:    14790.04 [#/sec] (mean)
Time per request:       13.523 [ms] (mean)
Time per request:       0.068 [ms] (mean, across all concurrent requests)
Transfer rate:          2224.28 [Kbytes/sec] received
                        6398.43 kb/s sent
                        8622.71 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0      11
Processing:     0   14   5.2     13      42
Waiting:        0   14   5.2     13      42
Total:          0   14   5.2     13      42

Percentage of the requests served within a certain time (ms)
  50%     13
  66%     16
  75%     17
  80%     18
  90%     20
  95%     21
  98%     24
  99%     27
 100%     42 (longest request)

I suggest you try ab with -k and take a look at tuning your system for lots of open sockets

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.