I am developing the web app and recently integrate the hangfire so resource intense tasks can be done in the background. However when I did load testing for a few hours I noticed the table grow up to 13GB for 10000 records in the job table. I know in the regular operation the background doesn't grow that much in the short time and I could make it so successful background tasks can be removed in a short time(by default 24 hours) but I just want to make sure what I am doing correct and hopefully there is a way to improve so job table doesn't grow so fast and huge. The following is the snippet of how I am adding the tasks to the queue.
`for (int i = 0; i < total; i += chunkNum)
{
var take = Math.Min(chunkNum, (total - i));
var chunkQuery = listReportRsrcTime.Skip(i).Take(take);
var chunk = listReportRsrcTime.Skip(i).Take(take);
var records = await GetReportItems(chunk, runControlId);
count += take;
backgroundIdList.Add(
BackgroundJob.Enqueue<IReportGenerateServices>(x => x.GeneratePayrollHourReport(records.ToList())));
}`
Make job arguments small and simple :)
Passing a large number of serialized records as job arguments likely blows up the table. The solution would be to pass only record identifiers (instead of the whole records themselves) or move the record extraction loop to the background job.
Hey I think this is what I was missing. Thank you very much!
Most helpful comment
Make job arguments small and simple :)
Passing a large number of serialized records as job arguments likely blows up the table. The solution would be to pass only record identifiers (instead of the whole records themselves) or move the record extraction loop to the background job.