Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using RabbitMQ.Client;
- using StoneMQ.Connection;
- using StoneMQ.Serializer;
- namespace StoneMQPerformanceTest
- {
- class DummySerializer : ISerializer
- {
- private int _size;
- public DummySerializer(int size)
- {
- _size = size;
- }
- public byte[] Marshal<T>(T o)
- {
- return new byte[_size];
- }
- public T Unmarshal<T>(byte[] bytes)
- {
- throw new NotImplementedException();
- }
- }
- internal class Program
- {
- public static void Main(string[] args)
- {
- var factory = new ConnectionFactory
- {
- HostName = "localhost",
- Port = 5672,
- UserName = "guest",
- Password = "guest",
- VirtualHost = "/"
- };
- using (var connection = factory.CreateConnection())
- {
- using (var channel = connection.CreateModel())
- {
- channel.QueueDeclare("test", true, autoDelete: false, exclusive: false);
- channel.ExchangeDeclare("test", "direct", true);
- channel.QueueBind("test", "test", "");
- }
- }
- SendBuilkWithRabbiMQClient(10000, 100);
- SendBuilkWithStoneMQ(10000, 100);
- var start = DateTime.Now;
- SendBuilkWithRabbiMQClient(10000, 10000);
- var end = DateTime.Now;
- Console.WriteLine("RabbitMQClient: " + (end - start));
- start = DateTime.Now;
- SendBuilkWithBulkStoneMQ(10000, 10000);
- end = DateTime.Now;
- Console.WriteLine("StoneMQ: " + (end - start));
- }
- public static void SendBuilkWithStoneMQ(int size, int number)
- {
- using (var connecion = new StoneMQConnection("app", "localhost", 5672, "guest", "guest"))
- {
- connecion.Serializer = new DummySerializer(size);
- var message = new byte[size];
- for (var i = 0; i < number; i++)
- {
- connecion.Publish("test", "test", message);
- }
- }
- }
- public static void SendBuilkWithBulkStoneMQ(int size, int number)
- {
- using (var connecion = new StoneMQConnection("app", "localhost", 5672, "guest", "guest"))
- {
- connecion.Serializer = new DummySerializer(size);
- var message = new byte[size];
- using (var publisher = connecion.Bulk())
- {
- for (var i = 0; i < number; i++)
- {
- publisher.Publish("test", "test", message);
- }
- }
- }
- }
- public static void SendBuilkWithRabbiMQClient(int size, int number)
- {
- var factory = new ConnectionFactory
- {
- HostName = "localhost",
- Port = 5672,
- UserName = "guest",
- Password = "guest",
- RequestedHeartbeat = 60,
- AutomaticRecoveryEnabled = true,
- NetworkRecoveryInterval = TimeSpan.FromMilliseconds(1000)
- };
- using (var connection = factory.CreateConnection())
- {
- using (var channel = connection.CreateModel())
- {
- var properties = channel.CreateBasicProperties();
- var message = new byte[size];
- properties.Persistent = true;
- properties.DeliveryMode = 2;
- for (var i = 0; i < number; i++)
- {
- channel.BasicPublish("test", "", true, properties, message);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement