Skip to content

Instantly share code, notes, and snippets.

@erikdubbelboer
Last active December 18, 2015 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikdubbelboer/5714305 to your computer and use it in GitHub Desktop.
Save erikdubbelboer/5714305 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"net/http"
)
var requests = 0
func printrequests() {
for ;; {
time.Sleep(1e9)
fmt.Println(requests)
requests = 0
}
}
func handler(w http.ResponseWriter, r *http.Request) {
requests++
w.Header().Set("Cache-Control", "no-cache, must-revalidate")
w.Header().Set("Expires" , "-1")
w.Header().Set("Connection" , "close")
w.Header().Set("Content-Type" , "text/javascript")
fmt.Fprintf(w, "/*ok*/")
/* Highjacking the connection and closing it manually doesn't help either.
f, canFlush := w.(http.Flusher)
if canFlush {
f.Flush()
}
conn, _, err := w.(http.Hijacker).Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
conn.Close()*/
}
func main() {
go printrequests()
http.HandleFunc("/", handler)
http.ListenAndServe("0.0.0.0:8000", nil)
}
# 10 minute interval file descriptor usage for simple.go
861
1000
1102
1275
1444
1550
1691
1916
2065
2261
2484
2694
2841
3011
3173
3361
3624
3856
3998
4071
4186
4357
4466
4657
4855
5032
5247
5457
5710
5893
6057
6251
6444
6687
6940
7138
7379
7606
7774
8006
8167
8373
8577
8741
9003
9188
9322
9582
9770
9935
10147
10394
10585
10666
10857
10983
11205
11417
11552
11770
12016
12201
12454
12590
12762
12920
13091
13261
13411
13559
13586
13616
13673
13727
13772
13856
13945
13999
14124
14167
14281
14317
14349
14431
# at this point it was using 363 MB of memory
package main
import (
"fmt"
"time"
"net/http"
)
var requests = 0
func printrequests() {
for ;; {
time.Sleep(1e9)
fmt.Println(requests)
requests = 0
}
}
func handler(w http.ResponseWriter, r *http.Request) {
requests++
w.Header().Set("Cache-Control", "no-cache, must-revalidate")
w.Header().Set("Expires" , "-1")
w.Header().Set("Connection" , "close")
w.Header().Set("Content-Type" , "text/javascript")
fmt.Fprint(w, "/*ok*/")
}
func main() {
go printrequests()
http.HandleFunc("/", handler)
s := &http.Server{
Addr: "0.0.0.0:8000",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1024*100,
}
s.ListenAndServe()
}
var http = require('http');
var requests = 0;
setInterval(function() {
console.log(requests);
requests = 0;
}, 1000);
http.createServer(function(request, response) {
++requests;
response.writeHead(200, {
'Content-Type' : 'text/javascript',
'Cache-Control' : 'no-cache, must-revalidate',
'Expires' : -1,
'Connection' : 'close'
});
response.end('/*ok*/');
}).listen(8000, '0.0.0.0'/*, 1023*/);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment