一个随便糊的用于模拟高延迟接口的go程序:修订间差异
来自三线的随记
小无编辑摘要 |
小无编辑摘要 |
||
第33行: | 第33行: | ||
食用方法: | 食用方法: | ||
go run sleep.go | go run sleep.go | ||
ps: 也可以通过tc命令实现 | |||
例如 | |||
[root@test ~]# tc qdisc add dev calic1c981f0768 root netem delay 2980ms | |||
[root@test ~]# tc qdisc add dev calide0993eb080 root netem delay 3010ms | |||
[[分类:Linux]] | [[分类:Linux]] | ||
[[分类:Golang]] | [[分类:Golang]] |
2022年8月24日 (三) 01:27的最新版本
package main import ( "fmt" "net/http" "time" ) func HelloHandler(w http.ResponseWriter, r *http.Request) { fmt.Println(r) min := 5 s := min * 60 fmt.Println(r.RemoteAddr, ": going to sleep",s ,"s(", min, " min)") for i := 1;i <= min; i++ { fmt.Println(r.RemoteAddr, ": sleeping", i, "* 60s") time.Sleep(60 *time.Second) } fmt.Fprintf(w, "Hello World") fmt.Println(r.RemoteAddr, ": End of sleep",r) } func common(w http.ResponseWriter, r *http.Request) { fmt.Println(r) fmt.Fprintf(w, "common - Hello World") } func main () { fmt.Println("listening: 8000") http.HandleFunc("/", HelloHandler) http.HandleFunc("/sleeper-sanxian/common", common) http.ListenAndServe(":8000", nil) }
食用方法:
go run sleep.go
ps: 也可以通过tc命令实现
例如
[root@test ~]# tc qdisc add dev calic1c981f0768 root netem delay 2980ms [root@test ~]# tc qdisc add dev calide0993eb080 root netem delay 3010ms