Created
June 8, 2023 21:07
-
-
Save bgrainger/f0b96e29c99cdf88f8de422879b2631e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MySqlConnector; | |
using System.Diagnostics; | |
var threadCount = args.Length == 1 && int.TryParse(args[0], out var tc) ? tc : 100; | |
var csb = new MySqlConnectionStringBuilder | |
{ | |
Server = // REDACTED | |
UserID = // REDACTED | |
Password = // REDACTED | |
MaximumPoolSize = (uint) threadCount, | |
ConnectionTimeout = 5, | |
}; | |
using (var connection = new MySqlConnection(csb.ConnectionString)) | |
{ | |
await connection.OpenAsync(); | |
using var command = connection.CreateCommand(); | |
command.CommandText = "CREATE SCHEMA IF NOT EXISTS test COLLATE utf8mb4_bin"; | |
await command.ExecuteNonQueryAsync(); | |
} | |
csb.Database = "test"; | |
var tasks = new List<Task>(); | |
for (int i = 0; i < threadCount; i++) | |
{ | |
tasks.Add(Task.Run(async () => | |
{ | |
while (true) | |
{ | |
using var connection = new MySqlConnection(csb.ConnectionString); | |
await connection.OpenAsync(); | |
var stopwatch = Stopwatch.StartNew(); | |
using var command = connection.CreateCommand(); | |
command.CommandText = """ | |
DROP TEMPORARY TABLE IF EXISTS test; | |
CREATE TEMPORARY TABLE test(id INT NOT NULL); | |
"""; | |
await command.ExecuteNonQueryAsync(); | |
stopwatch.Stop(); | |
Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} - {stopwatch.ElapsedMilliseconds}ms"); | |
} | |
})); | |
} | |
await Task.WhenAll(tasks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment