# Hangfire service is consuming excessive CPU and becomes unresponsive over time

**URL:** <https://discuss.hangfire.io/t/hangfire-service-is-consuming-excessive-cpu-and-becomes-unresponsive-over-time/11149>\
**Category:** bug?\
**Tags:** sql-server\
**Created:** [January 29, 2025, 3:02pm UTC](https://discuss.hangfire.io/t/hangfire-service-is-consuming-excessive-cpu-and-becomes-unresponsive-over-time/11149 "2025-01-29T15:02:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamxanadem](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hamxanadem](https://discuss.hangfire.io/u/hamxanadem)\
**Post date:** [January 29, 2025, 3:02pm UTC](https://discuss.hangfire.io/t/hangfire-service-is-consuming-excessive-cpu-and-becomes-unresponsive-over-time/11149/1 "2025-01-29T15:02:03Z")

</div>

- **High CPU Usage** : Hangfire is consuming **50% CPU** immediately upon startup.
- **Worker Configuration** : The **worker count is set to 4**.
- **Job Backlog** : There are **1.4 million pending jobs** in the database.
- **Storage Options** :

```auto
var options = new SqlServerStorageOptions
{
    UseRecommendedIsolationLevel = true,
    QueuePollInterval = TimeSpan.FromSeconds(30),
    JobExpirationCheckInterval = TimeSpan.FromHours(1),
    CountersAggregateInterval = TimeSpan.FromMinutes(5),
    DashboardJobListLimit = 50000,
    TransactionTimeout = TimeSpan.FromMinutes(1),
    SchemaName = "OHangfire",
    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(15),
};

```

- **Background Job Server Configuration** :

```auto
_server = new BackgroundJobServer(new BackgroundJobServerOptions() 
{ 
    WorkerCount = 4, 
    Queues = new[] { "1", "2", "3", "4", "5" }, 
    Activator = JobActivator.Current 
}, JobStorage.Current);

```

- **Job Execution Details** :
  - Jobs **send data to another system** via `HttpClient`, which is **created as a singleton**.
  - Job **enqueueing method** :

```auto
public void SendData(Data data)
{
    if (data != null)
    {
        BackgroundJob.Enqueue("1", () => SendNewData(data.Id, null));
    }
}

```

- **Job execution method** :

```auto
[Queue("1")]
[AutomaticRetry(Attempts = 0, DelaysInSeconds = new[] { 600, 1200, 1800 },
    OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public static void SendNewData(long dataId, PerformContext context)
{
    // Loads data from DB and sends it to another system.
}

```
