-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
55 lines (45 loc) · 970 Bytes
/
cli.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
package main
import (
"bufio"
"log"
"net"
"strconv"
"sync"
"time"
"github.com/n0_1/paxos/protocol"
)
var wg sync.WaitGroup
func main() {
for i := 1; i <= 9999; i++ {
conn, err := net.Dial("tcp", ":80")
if err != nil {
log.Println("dial ser error: ", err)
continue
}
wg.Add(1)
go handleConn(conn, uint64(i))
}
wg.Wait()
}
func handleConn(conn net.Conn, id uint64) {
id = 1111111111111111110 + id
conn.Write(protocol.AsmCmd("cre", strconv.Itoa(int(id))))
for {
start := time.Now()
conn.Write(protocol.AsmCmd("inc", strconv.Itoa(int(id))))
r := bufio.NewReader(conn)
recv, rerr := r.ReadSlice('\n')
if rerr != nil {
log.Println("read error: ", rerr)
break
}
recv = recv[:len(recv)-1]
if len(recv) > 0 && recv[len(recv)-1] == '\r' {
recv = recv[:len(recv)-1]
}
log.Println("recv content: ", string(recv))
d := time.Now().Sub(start)
log.Println(strconv.Itoa(int(id))+" inc spend: ", d)
}
wg.Done()
}