Created
March 21, 2016 12:56
-
-
Save slava-vishnyakov/a93808d7603057d96282 to your computer and use it in GitHub Desktop.
leaky gorequests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"os/exec" | |
"strings" | |
"time" | |
"github.com/parnurzeal/gorequest" | |
) | |
func testRequest() { | |
gorequest.New().Get("http://www.google.com").Set("Connection", "close").End() | |
} | |
func main() { | |
for { | |
go testRequest() | |
time.Sleep(1 * time.Second) | |
fmt.Println("Request done, open files =", countOpenFiles()) | |
} | |
} | |
func countOpenFiles() int { | |
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output() | |
if err != nil { | |
log.Fatal(err) | |
} | |
lines := strings.Split(string(out), "\n") | |
return len(lines) - 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request done, open files = 15 | |
Request done, open files = 17 | |
Request done, open files = 19 | |
Request done, open files = 21 | |
Request done, open files = 23 | |
Request done, open files = 25 | |
Request done, open files = 27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment