diff options
author | Peter Harris <git@peter.is-a-geek.org> | 2010-12-28 20:29:49 -0500 |
---|---|---|
committer | Peter Harris <git@peter.is-a-geek.org> | 2010-12-28 20:30:07 -0500 |
commit | 5bfc4aa02f512c21ef494f3fba387721153f5cce (patch) | |
tree | 55aa09739bb7c8039e29285f2b3dd616c9d3be78 | |
parent | cd8abe98db7307b3dec54abdfd9cd9d55aa706ec (diff) |
Allow nil error channel in WriteNoreplyRequest
Not allocating a channel at all doubles the speed of the noop test.
Now we're pushing just over 1M noop/sec (compared to x11perf/Xlib,
which pushes 13M noop/sec)
-rw-r--r-- | noop.go | 12 | ||||
-rw-r--r-- | xgob.go | 29 |
2 files changed, 21 insertions, 20 deletions
@@ -18,21 +18,11 @@ func main () { return } - err := make(chan interface{}) - go func (err chan interface{}) { - for { - e := <- err - if e != nil { - println("Unexpected error!") - } - } - }(err) - noopRequest := []byte{127, 0, 0, 1} fmt.Printf("Sending %d noop requests: ", *iter) for i := uint(0); i < *iter; i++ { - c.WriteNoreplyRequest(noopRequest, err) + c.WriteNoreplyRequest(noopRequest, nil) } c.Flush() fmt.Println("Done.") @@ -42,6 +42,7 @@ type Reply struct { type Connection struct { Setup ConnectionBlock Event chan Event + Error chan Error conn io.ReadWriteCloser out *bufio.Writer reply map[uint64]chan interface {} @@ -53,6 +54,7 @@ type Connection struct { } const events_before_readblock = 10000 +const errors_before_readblock = 10000 func parse_display (name string) (host string, protocol string, display int, screen int) { if len(name) == 0 { @@ -265,27 +267,35 @@ func (c *Connection) registerReply (reply chan interface{}) { defer c.replyMutex.Unlock() c.lastRequestWritten++ - c.reply[c.lastRequestWritten] = reply + if reply != nil { + c.reply[c.lastRequestWritten] = reply + } } func (c *Connection) postReply (seq uint64, reply interface{}) { c.replyMutex.Lock() defer c.replyMutex.Unlock() - if c.reply[seq] == nil { - println("Error: Unexpected sequence", seq) - return - } - if seq != c.lastSequenceRead { c.reply[c.lastSequenceRead] = nil, false } for i := c.lastSequenceRead + 1; i < seq; i++ { - c.reply[i] <- nil - c.reply[i] = nil, false + if target := c.reply[i]; target != nil { + target <- nil + c.reply[i] = nil, false + } } - c.reply[seq] <- reply + if target := c.reply[seq]; target != nil { + target <- reply + } else { + error, ok := reply.(Error) + if ok { + c.Error <- error + } else { + println("Unexpected reply to sequence", seq) + } + } c.lastSequenceRead = seq } @@ -338,6 +348,7 @@ func (c *Connection)connect_auth(name string, data string) { } c.out = bufio.NewWriter(c.conn) c.Event = make (chan Event, events_before_readblock) + c.Error = make (chan Error, errors_before_readblock) c.reply = make (map [uint64]chan interface{}) go c.read(in) } |