Created
November 18, 2013 14:19
-
-
Save btfak/7528491 to your computer and use it in GitHub Desktop.
负载工具性能测试,http server端
This file contains 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" | |
"net/http" | |
"os" | |
"strconv" | |
) | |
var data []byte | |
var length = 1024 | |
var count = 0 | |
func main() { | |
if len(os.Args) != 2 { | |
fmt.Fprintf(os.Stderr, "Usage: %s data-length\n", os.Args[0]) | |
os.Exit(1) | |
} | |
length, _ = strconv.Atoi(os.Args[1]) | |
makeData(0) | |
log.Println(" data-length:", len(data)) | |
http.HandleFunc("/print", printEnv) | |
http.ListenAndServe(":80", nil) | |
} | |
func printEnv(writer http.ResponseWriter, req *http.Request) { | |
writer.Write(data) | |
} | |
func makeData(count int) { | |
if count == length { | |
return | |
} | |
data = append(data, 'x') | |
count++ | |
makeData(count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment