use goroutine for reap handling

This commit is contained in:
siddontang 2014-10-30 09:03:58 +08:00
parent 8133cfdbb7
commit fcc8c9ae37
2 changed files with 23 additions and 18 deletions

View File

@ -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
}

View File

@ -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() {
// 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 {
// done <- err
return
if err == nil {
c.handleRequest(reqData)
}
c.handleRequest(reqData)
// done <- nil
// }()
done <- nil
}()
// err := <-done
// if err != nil {
// return
// }
// if c.conn == nil {
// return
// reqData, err := c.readRequest()
// if err == nil {
// c.handleRequest(reqData)
// }
err := <-done
if err != nil {
return
}
if c.conn == nil {
return
}
}
}