Skip to content

Commit 811d615

Browse files
committed
remove loop
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
1 parent 9ff963f commit 811d615

File tree

6 files changed

+22
-46
lines changed

6 files changed

+22
-46
lines changed

pkg/stream/aggregation_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ var _ = Describe("Compression algorithms", func() {
1818
}
1919

2020
message := &messageSequence{
21-
messageBytes: messagePayload,
22-
unCompressedSize: len(messagePayload),
23-
publishingId: 0,
21+
messageBytes: messagePayload,
22+
publishingId: 0,
2423
}
2524

2625
entries = &subEntries{

pkg/stream/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func (c *Client) heartBeat() {
432432
tickerHeartbeat.Stop()
433433
return
434434
case <-tickerHeartbeat.C:
435-
for c.socket.isOpen() {
435+
if c.socket.isOpen() {
436436
if time.Since(c.getLastHeartBeat()) > time.Duration(c.tuneState.requestedHeartbeat)*time.Second {
437437
v := atomic.AddInt32(&heartBeatMissed, 1)
438438
logs.LogWarn("Missing heart beat: %d", v)

pkg/stream/consumer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ func (consumer *Consumer) close(reason Event) error {
337337
consumer.closeHandler = nil
338338
}
339339

340-
if consumer.chunkForConsumer != nil {
341-
close(consumer.chunkForConsumer)
342-
consumer.chunkForConsumer = nil
343-
}
340+
//if consumer.chunkForConsumer != nil {
341+
close(consumer.chunkForConsumer)
342+
//consumer.chunkForConsumer = nil
343+
//}
344344

345345
if consumer.response.data != nil {
346346
close(consumer.response.data)

pkg/stream/coordinator.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ func (coordinator *Coordinator) NewProducer(
7373
status: open,
7474
pendingSequencesQueue: NewBlockingQueue[*messageSequence](dynSize),
7575
confirmMutex: &sync.Mutex{},
76-
pool: &sync.Pool{
77-
New: func() any {
78-
return &messageSequence{}
79-
},
80-
},
8176
}
8277
coordinator.producers[lastId] = producer
8378
return producer, err

pkg/stream/producer.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ type Producer struct {
7373
publishConfirmation chan []*ConfirmationStatus
7474

7575
pendingSequencesQueue *BlockingQueue[*messageSequence]
76-
pool *sync.Pool
7776
}
7877

7978
type FilterValue func(message message.StreamMessage) string
@@ -296,7 +295,6 @@ func (producer *Producer) processPendingSequencesQueue() {
296295
var lastError error
297296
for {
298297
select {
299-
300298
case msg, ok := <-producer.pendingSequencesQueue.GetChannel():
301299
{
302300
if !ok {
@@ -379,12 +377,12 @@ func (producer *Producer) fromMessageToMessageSequence(streamMessage message.Str
379377
if producer.options.IsFilterEnabled() {
380378
filterValue = producer.options.Filter.FilterValue(streamMessage)
381379
}
382-
fromPool := producer.pool.Get().(*messageSequence)
383-
fromPool.messageBytes = marshalBinary
384-
fromPool.publishingId = seq
385-
fromPool.filterValue = filterValue
380+
msqSeq := &messageSequence{}
381+
msqSeq.messageBytes = marshalBinary
382+
msqSeq.publishingId = seq
383+
msqSeq.filterValue = filterValue
386384

387-
return fromPool, nil
385+
return msqSeq, nil
388386

389387
}
390388

@@ -403,7 +401,6 @@ func (producer *Producer) Send(streamMessage message.StreamMessage) error {
403401
if len(messageSeq.messageBytes) > defaultMaxFrameSize {
404402
tooLarge := producer.unConfirmed.extractWithError(messageSeq.publishingId, responseCodeFrameTooLarge)
405403
producer.sendConfirmationStatus([]*ConfirmationStatus{tooLarge})
406-
producer.pool.Put(messageSeq)
407404
return FrameTooLarge
408405
}
409406

@@ -443,7 +440,6 @@ func (producer *Producer) BatchSend(batchMessages []message.StreamMessage) error
443440
for _, msg := range messagesSequence {
444441
m := producer.unConfirmed.extractWithError(msg.publishingId, responseCodeFrameTooLarge)
445442
producer.sendConfirmationStatus([]*ConfirmationStatus{m})
446-
producer.pool.Put(msg)
447443
}
448444
return FrameTooLarge
449445
}
@@ -457,13 +453,6 @@ func (producer *Producer) GetID() uint8 {
457453
}
458454

459455
func (producer *Producer) internalBatchSend(messagesSequence []*messageSequence) error {
460-
// remove form pool
461-
defer func() {
462-
for _, m := range messagesSequence {
463-
producer.pool.Put(m)
464-
}
465-
}()
466-
467456
return producer.internalBatchSendProdId(messagesSequence, producer.GetID())
468457
}
469458

@@ -535,8 +524,8 @@ func (producer *Producer) aggregateEntities(msgs []*messageSequence, size int, c
535524
// / the producer id is always the producer.GetID(). This function is needed only for testing
536525
// some condition, like simulate publish error.
537526
func (producer *Producer) internalBatchSendProdId(messagesSequence []*messageSequence, producerID uint8) error {
538-
//producer.options.client.socket.mutexMessageMap.Lock()
539-
//defer producer.options.client.socket.mutexMessageMap.Unlock()
527+
producer.options.client.socket.mutex.Lock()
528+
defer producer.options.client.socket.mutex.Unlock()
540529
if producer.getStatus() == closed {
541530
return fmt.Errorf("producer id: %d closed", producer.id)
542531
}

pkg/stream/producer_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ var _ = Describe("Streaming Producers", func() {
315315

316316
})
317317

318-
It("Smart Send/Close", Focus, func() {
318+
It("Smart Send/Close", func() {
319319
producer, err := testEnvironment.NewProducer(testProducerStream, nil)
320320
Expect(err).NotTo(HaveOccurred())
321321
var messagesReceived int32
@@ -570,17 +570,15 @@ var _ = Describe("Streaming Producers", func() {
570570
for i := 0; i < 1; i++ {
571571
s := make([]byte, 50)
572572
messagesSequence[i] = &messageSequence{
573-
messageBytes: s,
574-
unCompressedSize: len(s),
573+
messageBytes: s,
575574
}
576575
}
577576

578577
msg := amqp.NewMessage([]byte("test"))
579578
msg.SetPublishingId(1)
580579
messageBytes, _ := msg.MarshalBinary()
581580
messagesSequence[0] = &messageSequence{
582-
messageBytes: messageBytes,
583-
unCompressedSize: len(messageBytes),
581+
messageBytes: messageBytes,
584582
}
585583

586584
// 200 producer ID doesn't exist
@@ -659,8 +657,7 @@ var _ = Describe("Streaming Producers", func() {
659657
for i := 0; i < 201; i++ {
660658
s := make([]byte, 50)
661659
messagesSequence[i] = &messageSequence{
662-
messageBytes: s,
663-
unCompressedSize: len(s),
660+
messageBytes: s,
664661
}
665662
}
666663

@@ -676,8 +673,7 @@ var _ = Describe("Streaming Producers", func() {
676673

677674
s := make([]byte, 50)
678675
messagesSequence[i] = &messageSequence{
679-
messageBytes: s,
680-
unCompressedSize: len(s),
676+
messageBytes: s,
681677
}
682678
}
683679

@@ -692,8 +688,7 @@ var _ = Describe("Streaming Producers", func() {
692688
for i := 0; i < 1; i++ {
693689
s := make([]byte, 50)
694690
messagesSequence[i] = &messageSequence{
695-
messageBytes: s,
696-
unCompressedSize: len(s),
691+
messageBytes: s,
697692
}
698693
}
699694

@@ -708,8 +703,7 @@ var _ = Describe("Streaming Producers", func() {
708703
for i := 0; i < 1000; i++ {
709704
s := make([]byte, 50)
710705
messagesSequence[i] = &messageSequence{
711-
messageBytes: s,
712-
unCompressedSize: len(s),
706+
messageBytes: s,
713707
}
714708
}
715709

@@ -724,8 +718,7 @@ var _ = Describe("Streaming Producers", func() {
724718
for i := 0; i < 14; i++ {
725719
s := make([]byte, 50)
726720
messagesSequence[i] = &messageSequence{
727-
messageBytes: s,
728-
unCompressedSize: len(s),
721+
messageBytes: s,
729722
}
730723
}
731724

0 commit comments

Comments
 (0)