/
main.go
71 lines (63 loc) · 1.33 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
"strconv"
"time"
go_nfs "github.com/mit-pdos/go-nfsd/nfs"
"github.com/mit-pdos/go-nfsd/nfstypes"
)
const BENCHDISKSZ uint64 = 100 * 1000
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
PLookup()
}
func Lookup(clnt *go_nfs.NfsClient, dirfh nfstypes.Nfs_fh3, name string) {
reply := clnt.LookupOp(dirfh, name)
if reply.Status != nfstypes.NFS3_OK {
panic("Lookup")
}
fh := reply.Resok.Object
attr := clnt.GetattrOp(fh)
if attr.Status != nfstypes.NFS3_OK {
panic("Lookup")
}
}
func PLookup() {
const N = 1 * time.Second
const NTHREAD = 4
for i := 1; i <= NTHREAD; i++ {
res := go_nfs.Parallel(i, BENCHDISKSZ,
func(clnt *go_nfs.NfsClient, dirfh nfstypes.Nfs_fh3) int {
s := strconv.Itoa(i)
name := "x" + s
clnt.CreateOp(dirfh, name)
start := time.Now()
i := 0
for true {
Lookup(clnt, dirfh, name)
i++
t := time.Now()
elapsed := t.Sub(start)
if elapsed >= N {
break
}
}
return i
})
fmt.Printf("Lookup: %d file in %d usec with %d threads\n",
res, N.Nanoseconds()/1e3, i)
}
}