Skip to content

Commit

Permalink
Update PingPong Benchmark (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Havret authored Jun 3, 2024
1 parent 40763d5 commit 7bc6735
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,6 @@ Both the benchmark applications and the broker are hosted on the same machine, w

The baseline for these benchmarks is set using the official [Apache NMS.AMQP library](https://github.com/apache/activemq-nms-amqp).

### Request-Reply (PingPong) Benchmark

This benchmark measures the performance in a request-reply messaging scenario. The test setup involves two components, `Ping` and `Pong`:

- **`Ping`**: Sends a message to `Pong` and starts a timer.
- **`Pong`**: Receives the message and responds back immediately.

The performance is assessed by measuring the round-trip time and calculating the throughput in terms of round-trips per second, over the course of sending and receiving 10,000 messages.

| Library | Round-trips per Second |
|------------------------|------------------------|
| ArtemisNetCoreClient | 1990.34 |
| NMS.AMQP | 948.13 |

<div align="center">
<img src="./readme/PingPong_Benchmark.svg" alt="Benchmark Results Diagram"/>
</div>

### Throughput

This benchmark assesses the ability of the library to handle large volumes of messages efficiently, focusing on both sending and receiving processes:
Expand All @@ -151,6 +133,24 @@ Results show how quickly each library can transmit and receive messages:
<img src="./readme/Throughput_Benchmark_2.svg" alt="Benchmark Results Diagram"/>
</div>

### Request-Reply (PingPong) Benchmark

This benchmark measures the performance in a request-reply messaging scenario. The test setup involves two components, `Ping` and `Pong`:

- **`Ping`**: Sends a message to `Pong` and starts a timer.
- **`Pong`**: Receives the message and responds back immediately.

The performance is assessed by measuring the round-trip time and calculating the throughput in terms of round-trips per second, over the course of sending and receiving 10,000 messages.

| Library | Round-trips per Second |
|------------------------|------------------------|
| ArtemisNetCoreClient | 2,205.86 |
| NMS.AMQP | 905.55 |

<div align="center">
<img src="./readme/PingPong_Benchmark.svg" alt="Benchmark Results Diagram"/>
</div>

## Running the tests

To run the tests, you need an Apache ActiveMQ Artemis server. The server can be hosted in a Docker container.
Expand Down
10 changes: 6 additions & 4 deletions benchmark/PingPong_ArtemisNetCoreClient/Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public Task<Stats> Start(int numberOfMessages, int skipMessages)
_skipMessages = skipMessages;
_stopwatch.Start();
_tsc = new TaskCompletionSource<Stats>();
var pingMessage = new Message { Body = "Ping"u8.ToArray() };
_producer.SendMessageAsync(pingMessage);
var pingMessage = new Message { Body = "Ping"u8.ToArray(), Durable = false };
_producer.SendMessage(pingMessage);
return _tsc.Task;
}

Expand All @@ -73,9 +73,11 @@ private Task ConsumerLoop()
}
else
{
var pingMessage = new Message { Body = "Ping"u8.ToArray() };
await _producer.SendMessageAsync(pingMessage, _cts.Token);
var pingMessage = new Message { Body = "Ping"u8.ToArray(), Durable = false };
// ReSharper disable once MethodHasAsyncOverload
_producer.SendMessage(pingMessage);
}
await _consumer.AcknowledgeAsync(msg.MessageDelivery, _cts.Token);
}
}
Expand Down
5 changes: 3 additions & 2 deletions benchmark/PingPong_ArtemisNetCoreClient/Pong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ private Task ConsumerLoop()
while (!_cts.IsCancellationRequested)
{
var pingMsg = await _consumer.ReceiveMessageAsync(_cts.Token);
var pongMessage = new Message { Body = "Pong"u8.ToArray() };
await _producer.SendMessageAsync(pongMessage, _cts.Token);
var pongMessage = new Message { Body = "Pong"u8.ToArray(), Durable = false };
// ReSharper disable once MethodHasAsyncOverload
_producer.SendMessage(pongMessage);
await _consumer.AcknowledgeAsync(pingMsg.MessageDelivery, _cts.Token);
}
}
Expand Down
4 changes: 3 additions & 1 deletion benchmark/PingPong_NMS.AMQP/Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ private void OnMessage(IMessage message)
if (_counter == _numberOfMessages)
{
_stopwatch.Stop();
_tsc.SetResult(new Stats { MessagesCount = _counter, Elapsed = _stopwatch.Elapsed });
_tsc?.SetResult(new Stats { MessagesCount = _counter, Elapsed = _stopwatch.Elapsed });
}
else
{
var pingMessage = _messageProducer.CreateBytesMessage("Ping"u8.ToArray());
pingMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent;
_messageProducer.Send(pingMessage);
}
}
Expand All @@ -52,6 +53,7 @@ public Task<Stats> Start(int numberOfMessages, int skipMessages)
_tsc = new TaskCompletionSource<Stats>(TaskCreationOptions.RunContinuationsAsynchronously);
_stopwatch.Start();
var pingMessage = _messageProducer.CreateBytesMessage("Ping"u8.ToArray());
pingMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent;
_messageProducer.Send(pingMessage);
return _tsc.Task;
}
Expand Down
1 change: 1 addition & 0 deletions benchmark/PingPong_NMS.AMQP/Pong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public Pong(IConnectionFactory connectionFactory)
private void OnMessage(IMessage message)
{
var pongMessage = _session.CreateBytesMessage("Pong"u8.ToArray());
pongMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent;
_messageProducer.Send(pongMessage);
}

Expand Down
2 changes: 1 addition & 1 deletion readme/PingPong_Benchmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7bc6735

Please sign in to comment.