summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Harris <git@peter.is-a-geek.org>2010-12-28 20:12:08 -0500
committerPeter Harris <git@peter.is-a-geek.org>2010-12-28 20:30:07 -0500
commitcd8abe98db7307b3dec54abdfd9cd9d55aa706ec (patch)
tree2065cd3a59a264cb83634e3229240c494deda76d
parente76358414010b587db5d2e0a7e3775a2232edf89 (diff)
Pass channel into WriteNoreplyRequest
This speeds up noop.go 3x (or 1.5x with the GC disabled)
-rw-r--r--noop.go12
-rw-r--r--xgob.go38
2 files changed, 34 insertions, 16 deletions
diff --git a/noop.go b/noop.go
index 43ae334..3b9aae3 100644
--- a/noop.go
+++ b/noop.go
@@ -18,11 +18,21 @@ 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)
+ c.WriteNoreplyRequest(noopRequest, err)
}
c.Flush()
fmt.Println("Done.")
diff --git a/xgob.go b/xgob.go
index 3f06855..a9e5d39 100644
--- a/xgob.go
+++ b/xgob.go
@@ -364,19 +364,7 @@ func (c *Connection) Disconnect () {
c.conn = nil
}
-func (c *Connection) WriteMultiRequest (req []byte, expected int) chan interface{} {
- if c == nil || c.conn == nil {
- return nil
- }
-
- replier := true
- if (expected < 1) {
- expected = 1
- replier = false
- }
-
- rv := make(chan interface {}, expected)
-
+func (c *Connection) writeRequest (req []byte, replier bool, rv chan interface{}) {
c.writeMutex.Lock()
defer c.writeMutex.Unlock()
@@ -392,12 +380,32 @@ func (c *Connection) WriteMultiRequest (req []byte, expected int) chan interface
c.lastReplierSent = c.lastRequestWritten
}
}
+}
+
+func (c *Connection) WriteMultiRequest (req []byte, expected int) chan interface{} {
+ if c == nil || c.conn == nil {
+ return nil
+ }
+
+ replier := true
+ if (expected < 1) {
+ expected = 1
+ replier = false
+ }
+
+ rv := make(chan interface {}, expected)
+
+ c.writeRequest(req, replier, rv)
return rv
}
-func (c *Connection) WriteNoreplyRequest (req []byte) chan interface{} {
- return c.WriteMultiRequest(req, 0)
+func (c *Connection) WriteNoreplyRequest (req []byte, rv chan interface{}) {
+ if c == nil || c.conn == nil {
+ return
+ }
+
+ c.writeRequest(req, false, rv)
}
func (c *Connection) WriteReplyRequest (req []byte) chan interface{} {