コード例 #1
0
ファイル: server.go プロジェクト: lijie/siriusdb
// ServeConn runs the server on a single connection.
// ServeConn blocks, serving the connection until the client hangs up.
// The caller typically invokes ServeConn in a go statement.
// ServeConn uses the gob wire format (see package gob) on the
// connection.  To use an alternate codec, use ServeCodec.
func (server *Server) ServeConn(conn io.ReadWriteCloser) {
	srv := &siriusServerCodec{
		rwc: conn,
		dec: sirius_net.NewBuffer(conn),
		enc: sirius_net.NewBuffer(conn),
	}
	server.ServeCodec(srv)
}
コード例 #2
0
ファイル: rpc.go プロジェクト: lijie/siriusdb
// NewClient returns a new Client to handle requests to the
// set of services at the other end of the connection.
// It adds a buffer to the write side of the connection so
// the header and payload are sent as a unit.
func NewClient(conn io.ReadWriteCloser) *Client {
	client := &siriusClientCodec{
		rwc: conn,
		dec: sirius_net.NewBuffer(conn),
		enc: sirius_net.NewBuffer(conn),
	}
	return NewClientWithCodec(client)
}
コード例 #3
0
ファイル: dba_benchmark.go プロジェクト: lijie/siriusdb
func recvloop(conn *net.TCPConn, count int, done chan int) {
	buffer := sirius_net.NewBuffer(conn)
	var req *request
	var ok bool

	if enableCPUProfiler {
		f, _ := os.OpenFile("/tmp/go_profile", os.O_CREATE|os.O_RDWR, 0666)
		pprof.StartCPUProfile(f)
	}

	delayFast := 0
	delay50 := 0
	delay100 := 0
	delay500 := 0
	delaySlow := 0
	var delay int64

	for count > 0 {
		err := buffer.ReadMsg(nil)
		if err != nil {
			break
		}
		count--

		reqlock.Lock()
		req, ok = reqmap[buffer.Header.Seq]
		delete(reqmap, buffer.Header.Seq)
		reqlock.Unlock()
		if !ok {
			log.Printf("unknown seq %d\n", buffer.Header.Seq)
			continue
		}

		delay = time.Now().Sub(req.start).Nanoseconds()
		if delay > 1000000000 {
			delaySlow++
		} else if delay > 500000000 {
			delay500++
		} else if delay > 100000000 {
			delay100++
		} else if delay > 50000000 {
			delay50++
		} else {
			delayFast++
		}

		req.callback(&buffer.Header, buffer.Body())
	}

	fmt.Printf("delay stat %d %d %d %d %d\n", delayFast, delay50, delay100, delay500, delaySlow)
	if enableCPUProfiler {
		pprof.StopCPUProfile()
	}
	done <- 1
}
コード例 #4
0
ファイル: dba_benchmark.go プロジェクト: lijie/siriusdb
func writeData(conn net.Conn) {
	var req *request
	buffer := sirius_net.NewBuffer(conn)
	for i := 0; i < testCount; i++ {
		req = &request{
			start: time.Now(),
			seq:   uint32(i),
			callback: func(h *sirius_net.Header, b []byte) {
				if h.Err != 0 {
					fmt.Printf("write req %d error %d\n", h.Seq, h.Err)
				}
			},
		}
		reqlock.Lock()
		reqmap[uint32(i)] = req
		reqlock.Unlock()
		writePlayer(conn, buffer, uint32(i))
	}
}
コード例 #5
0
ファイル: dba_benchmark.go プロジェクト: lijie/siriusdb
func readData(conn net.Conn) {
	var req *request
	buffer := sirius_net.NewBuffer(conn)
	for i := 0; i < testCount; i++ {
		req = &request{
			start: time.Now(),
			seq:   uint32(i),
			callback: func(h *sirius_net.Header, b []byte) {
				if h.Err != 0 {
					fmt.Printf("read req %d error %d\n", h.Seq, h.Err)
				}
			},
		}
		reqlock.Lock()
		reqmap[uint32(i)] = req
		reqlock.Unlock()
		readPlayer(conn, buffer, uint32(i))

		if i > 0 && i%sendSpeed == 0 {
			time.Sleep(1 * time.Second)
		}
	}
}