I am wondering what the expected performance is on average for a single Enqueue call using SQL Server storage? I am seeing anywhere from 150ms to 500ms. Because of this latency, Hangfire is processing work faster than I can generate it, which is hindering me from maximizing my available resources. Any suggestions for faster queueing?
I have now set this up using an empty localdb and am queueing an empty method call. I am averaging only 5 creates per second when calling Enqueue in a 500 iteration loop. When running profiler, it appears that each set of database operations is taking a total of 100-300ms, which would explain the 5 per second performance. Is there some settings on SQL Server that may need adjusting? I just don’t understand how I can be so far off the expected throughput.
Controller:
public void EmptyMethod() {}
public void TestHangfire() {
var timer = new Stopwatch();
timer.Start();
for (var i = 0; i <= 500; i++) {
BackgroundJob.Enqueue(() => EmptyMethod());
}
//Get the elapsed time as a TimeSpan value.
var ts = timer.Elapsed;
//Format and display the TimeSpan value.
var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
Debug.WriteLine("RunTime " + elapsedTime);
timer.Stop();
}
Connection String:
<add name="Hangfire" connectionString="Server=(localdb)\HangFireInstance;Database=HangFireLocal;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
This might have been obvious, but I finally realized it was as a result of running with debugging. Without debugging I am seeing the expected throughput.