matryer / vice

Go channels at horizontal scale (powered by message queues)
https://medium.com/@matryer/introducing-vice-go-channels-across-many-machines-bcac1147d7e2
Apache License 2.0
1.54k stars 79 forks source link

nats: use buffered channels to improve performance #12

Closed HeavyHorst closed 7 years ago

HeavyHorst commented 7 years ago

The nats performance improve a lot with this little change:

I changed the sendloop in test.go to this

    for i := 0; i < 10000; i++ {
        msg := []byte(fmt.Sprintf("message %d", i+1))
        wg.Add(3)
        transport.Send("vicechannel1") <- msg
        transport.Send("vicechannel2") <- msg
        transport.Send("vicechannel3") <- msg
    }

to send 10000 messages instead of 100 down each channel

Before:

=== RUN   TestTransport
=== RUN   TestTransport/testStandardTransportBehaviour
=== RUN   TestTransport/testSendChannelsDontBlock
--- PASS: TestTransport (2.34s)
    --- PASS: TestTransport/testStandardTransportBehaviour (2.34s)
    --- PASS: TestTransport/testSendChannelsDontBlock (0.00s)
=== RUN   TestReceive
--- PASS: TestReceive (0.01s)
=== RUN   TestSend
--- PASS: TestSend (0.01s)
PASS

After:

=== RUN   TestTransport
=== RUN   TestTransport/testStandardTransportBehaviour
=== RUN   TestTransport/testSendChannelsDontBlock
--- PASS: TestTransport (0.09s)
    --- PASS: TestTransport/testStandardTransportBehaviour (0.09s)
    --- PASS: TestTransport/testSendChannelsDontBlock (0.00s)
=== RUN   TestReceive
--- PASS: TestReceive (0.01s)
=== RUN   TestSend
--- PASS: TestSend (0.01s)
PASS
matryer commented 7 years ago

Amazing.