diff --git a/server/client.go b/server/client.go index 7ba86ec..47d8f85 100644 --- a/server/client.go +++ b/server/client.go @@ -64,7 +64,7 @@ type client struct { lastLogID uint64 - reqErr chan error + // reqErr chan error buf bytes.Buffer @@ -82,7 +82,7 @@ func newClient(app *App) *client { c.ldb = app.ldb c.db, _ = app.ldb.Select(0) //use default db - c.reqErr = make(chan error) + // c.reqErr = make(chan error) return c } diff --git a/server/client_resp.go b/server/client_resp.go index 00d0e95..a7ec21c 100644 --- a/server/client_resp.go +++ b/server/client_resp.go @@ -77,26 +77,31 @@ func (c *respClient) run() { c.app.removeSlave(c.client, handleQuit) }() - // done := make(chan error) + done := make(chan error) for { - // go func() { - reqData, err := c.readRequest() + // I still don't know why use goroutine can improve performance + // if someone knows and benchamrks with another different result without goroutine, please tell me + go func() { + reqData, err := c.readRequest() + if err == nil { + c.handleRequest(reqData) + } + + done <- nil + }() + + // reqData, err := c.readRequest() + // if err == nil { + // c.handleRequest(reqData) + // } + + err := <-done if err != nil { - // done <- err return } - - c.handleRequest(reqData) - // done <- nil - // }() - - // err := <-done - // if err != nil { - // return - // } - // if c.conn == nil { - // return - // } + if c.conn == nil { + return + } } }