示例#1
0
func BenchmarkRpc(b *testing.B) {
	timing := time2.Timing()
	for i := 0; i < b.N; i++ {
		fmt.Println(b.N)
		var out Out
		timing()
		cli.Call("Math.Add", In{i, i + 1}, &out)
		fmt.Println("call", timing())
		if out.Sum != 2*i+1 {
			b.Fatal("bad result")
		}
	}
}
示例#2
0
func (p *protocol) ReadHeader(r *bufio.Reader) (hdr Header, err error) {
	timing := time2.Timing()
	line, err := r.ReadSlice('\r')
	fmt.Println("Readline", timing(), len(line))
	if err != nil {
		return Header{}, p.sanitizeErr(err)
	}
	err = p.assumeByte(r, '\n')
	fmt.Println("Readbyte", timing(), len(line))
	if err != nil {
		return Header{}, p.sanitizeErr(err)
	}

	hdr, err = p.parseHeader(line)
	fmt.Println("ParseHeader", timing())
	return hdr, err
}
示例#3
0
func BenchmarkZRpc(b *testing.B) {
	timing := time2.Timing()
	for i := 0; i < b.N; i++ {
		fmt.Println(b.N)
		timing()
		replies, err := zcli.Call("Add", i, i+1)
		fmt.Println("Call", timing())
		if err != nil {
			b.Fatal(err)
		}
		var e string
		var sum int
		err = replies(&sum, &e)
		fmt.Println("replies", timing())
		if err != nil {
			b.Fatal(err)
		}
		b.Log(e)
		if sum != 2*i+1 {
			b.Errorf("bad result: %d, expect %d", sum, 2*i+1)
		}
	}
}
示例#4
0
文件: server.go 项目: clrpc/clrpc-go
func (s *Server) serveConn(conn net.Conn) {
	r := bufio.NewReader(conn)
	w := bufio.NewWriter(conn)
	timing := time2.Timing()
	for {
		req := request{
			Server:    s,
			r:         r,
			nextParam: true,
		}
		hdr, err := req.protocol.ReadHeader(req.r)
		fmt.Println("readHeader", timing())
		if err != nil {
			conn.Close()
			break
		}

		resp := response{
			service: hdr.Service,
			seq:     hdr.Seq,

			Server: s,
			w:      w,
		}

		service, has := s.services[hdr.Service]
		if !has {
			resp.setHeader(errors.CodeServiceNotFound)
		} else {
			service(req.Params, resp.Replies)
			fmt.Println("call", timing())
		}
		resp.protocol.WriteEnd(resp.w)
		fmt.Println("end", timing())
	}
}