Hangfire + Redis, unexpected latency

Hi,

We’re using Hangfire and its paid Redis extension. We switched from Postgres to Redis to reduce latency we’ve been experiencing (up to 10 seconds), but it hasn’t changed much.

I can observe the delay between the scheduled start (scheduled by BackgroundJob.Schedule(), using CRON) and the actual start - it’s something like a few seconds. Sometimes it’s less than a second, and sometimes it can be even 10 seconds - it really goes between those two values.

Server shouldn’t be under pressure, because there is just one other job that is scheduled to start every 20 seconds. That one sometimes misfires, but it’s not crucial to the system. However, we need latency of <1s.

The Startup.cs looks something like this:

public void ConfigureServices(IServiceCollection services)
{
  services.AddAuthentication();

  services.AddControllers();

  ...

  var redisConnectionString = _configuration.GetConnectionString("RedisConnection");
  services.AddHangfire(configuration =>
    configuration.UseRedisStorage(redisConnectionString));
  services.AddHangfireServer();

  ...

  services.AddHostedService<Scheduler>();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
  ...
  app.UseRouting();

  app.UseEndpoints(endpoints =>
  {
    endpoints.MapControllers();
  });

  app.UseHangfireServer();

  app.UseHangfireDashboard("/hangfire", new DashboardOptions
  {
    Authorization = new[] { new HangFireDashboardJwtAuthorizationFilter() }
  });
}