Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Created July 2, 2014 15:09
Show Gist options
  • Save shawnweisfeld/16fe6afe0671edf3e163 to your computer and use it in GitHub Desktop.
Save shawnweisfeld/16fe6afe0671edf3e163 to your computer and use it in GitHub Desktop.
azure service bus throughput test
static void Main(string[] args)
{
ResetTheQueue();
PerformTheTest();
Console.ReadKey();
}
private static void PerformTheTest()
{
Console.ForegroundColor = ConsoleColor.Green;
int iterationCount = 100000;
int senders = 10;
int iteration = 0;
Stopwatch stopwatch = new Stopwatch();
var message = RandomString(2 * 1024);
var clients = new List<QueueClient>();
for (int i = 0; i < senders; i++)
{
clients.Add(QueueClient.CreateFromConnectionString(_connectionString, _testQueueName));
}
stopwatch.Start();
var tasks = new List<Task>();
while (iteration < iterationCount)
{
tasks.Add(clients[iteration % senders].SendAsync(new BrokeredMessage(message)));
iteration++;
Console.Write(".");
}
Task.WaitAll(tasks.ToArray());
stopwatch.Stop();
Console.WriteLine(" Done!");
Console.WriteLine("{0} Elapsed Seconds", stopwatch.Elapsed.TotalSeconds);
Console.WriteLine("{0} Msgs per second", iterationCount / stopwatch.Elapsed.TotalSeconds);
}
private static void ResetTheQueue()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Reseting the queue . . . Please wait!");
NamespaceManager ns = NamespaceManager.CreateFromConnectionString(_connectionString);
if (ns.QueueExists(_testQueueName))
{
ns.DeleteQueue(_testQueueName);
}
ns.CreateQueue(new QueueDescription(_testQueueName)
{
EnableExpress = true,
EnablePartitioning = true,
});
System.Threading.Thread.Sleep(1000);
Console.WriteLine("Queue reset complete!");
}
private static Random random = new Random((int)DateTime.Now.Ticks);
private static string RandomString(int size)
{
StringBuilder builder = new StringBuilder();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
return builder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment