0

I am having performance issue with batch Apex. Trying to reduce the waiting time. It goes to holding for 5mins .

There is scheduled Apex that was queued along with that. However goes to "Abort" at the end of 5th mins and then starts the batch apex.

*enter image description here*

I have lot of question here. I suppose batch apex is always last in queue hence waiting for scheduled apex to run first. However i don't know why scheduled apex in queued for so much time. Does it give priority to Future. Even so the "future" job start at 12:48 when "Scheduled Apex" queued at 12:46. 1. Why there is a lag of 2 mins between future jobs and also to start? 2. is there any other efficient way queueing?

Forgot to mention all those jobs are managed. I don't have access to code. I need to pin point the issue.

Is there anyway I can turn in to reduce the "holding" time of "Batch Apex". Thanks in advance

1 Answer 1

4

You should definitely look at the official documentation on Batch Apex and Apex Scheduler, you will get much more details from there. Highlighting few important things from these documentation, which can help you to understand this behavior based on your queries.

As for what you asked:

However i don't know why scheduled apex in queued for so much time. Does it give priority to Future.

is there any other efficient way queuing?

Refer to this excerpt from the Apex Scheduler documentation:

Salesforce schedules the class for execution at the specified time. Actual execution may be delayed based on service availability.

and same from Batch Apex:

When you call Database.executeBatch, Salesforce adds the process to the queue. Actual execution can be delayed based on service availability.

So there's no guarantee, at what time the jobs will start. It all depends on Salesforce's algorithms and resource availability.

As for your this question:

Is there anyway I can turn in to reduce the "holding" time of "Batch Apex".

Refer to the section "Holding Batch Jobs in the Apex Flex Queue" in the Batch Apex documentation. If you have Apex Flex Queue enabled for your org, then you do have a way to "reorder" the jobs. Excerpt below:

While submitted jobs have a status of Holding, you can reorder them in the Salesforce user interface to control which batch jobs are processed first. To do so, from Setup, enter Apex Flex Queue in the Quick Find box, then select Apex Flex Queue.

However this still does not guarantee immediate processing, jobs are only prioritized but are executed only when resources are available. Refer to later text in the same documentation:

You can reorder jobs in the Apex flex queue to prioritize jobs. For example, you can move a batch job up to the first position in the holding queue to be processed first when resources become available. Otherwise, jobs are processed “first-in, first-out”—in the order in which they’re submitted.


In summary, you can design your jobs to be scheduled at a time, but you cannot guarantee if they will execute exactly at the time you schedule those because of the resource availability.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .