-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.go
58 lines (42 loc) · 930 Bytes
/
mem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
// ex: set tabstop=4 expandtab:
// remember set modeline in vimrc
import (
"os"
"fmt"
"runtime"
"runtime/debug"
"strconv"
"net/http"
_ "net/http/pprof"
)
type DAT struct {
dat [1000 * 1000]byte
}
var mm = make(map[int]*DAT)
func hStart(w http.ResponseWriter, req *http.Request) {
var i int
s := req.FormValue("cnt")
i, _ = strconv.Atoi(s)
for ; i > 0; i-- {
mm[i] = new(DAT)
}
fmt.Fprintf(w, "start %v!", s)
}
func hReset(w http.ResponseWriter, req *http.Request) {
mm = make(map[int]*DAT)
act := req.FormValue("act")
switch act {
case "gc":
runtime.GC()
case "fm":
debug.FreeOSMemory()
}
fmt.Fprintf(w, "hello, world!\n")
}
func main() {
go http.ListenAndServe(os.Args[1] + "1", nil)
http.HandleFunc("/start", hStart)
http.HandleFunc("/reset", hReset)
http.ListenAndServe(os.Args[1], nil)
}