Skip to content

Commit a70bc1e

Browse files
Fix consumer performance bottleneck (#198)
* Fix readUint8Array The binary.Read method falls back to using the reflect package on *[]uint8 data types, which is much slower. This seems to fix the consumer performance on big messages (> 100B), but not on small ones. * Add message bytes test Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com> --------- Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com> Co-authored-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
1 parent 4aaad89 commit a70bc1e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pkg/stream/buffer_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ func readString(readerStream io.Reader) string {
5959

6060
func readUint8Array(readerStream io.Reader, size uint32) []uint8 {
6161
var res = make([]uint8, size)
62-
_ = binary.Read(readerStream, binary.BigEndian, &res)
62+
_ = binary.Read(readerStream, binary.BigEndian, res)
6363
return res
6464
}

pkg/stream/consumer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ var _ = Describe("Streaming Consumers", func() {
437437
}
438438
}(chConfirm, producer)
439439
Expect(err).NotTo(HaveOccurred())
440-
msg := amqp.NewMessage([]byte("message"))
440+
msg := amqp.NewMessage([]byte{0x00, 0x0e, 0x01, 0x0f, 0x05, 0x08, 0x04, 0x03})
441441
msg.Properties = &amqp.MessageProperties{
442442
MessageID: nil,
443443
UserID: nil,
@@ -466,6 +466,7 @@ var _ = Describe("Streaming Consumers", func() {
466466
Expect(message.Properties.To).To(Equal("ToTest"))
467467
Expect(message.Properties.ContentType).To(Equal("ContentTypeTest"))
468468
Expect(message.Properties.ContentEncoding).To(Equal("ContentEncodingTest"))
469+
Expect(message.Data[0]).To(Equal([]byte{0x00, 0x0e, 0x01, 0x0f, 0x05, 0x08, 0x04, 0x03}))
469470

470471
}, NewConsumerOptions().SetOffset(OffsetSpecification{}.First()).SetConsumerName("consumer_test"))
471472
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)