3

I know that the following limits exist in salesforce:

  • Number of synchronous concurrent transactions for long-running transactions that last longer than 5 seconds for each org : Limit 10
  • Concurrent API Request Limits for concurrent requests (calls) with a duration of 20 seconds or longer : Limit 5 in Developer Edition and Trial orgs

I created the following rest resource:

    @RestResource(urlMapping='/TEST/*')
global with sharing class MyRestResource {
    @HttpPost
    global static String doPost(String secondSleepTime,String callName) {
        try{
            System.debug('@@@ START callName='+callName);
            Long startTime = DateTime.now().getTime();
            Integer secSleepTime=Integer.valueOf(secondSleepTime);
            MyRestResource.sleep(secSleepTime);
            Long finishTime = DateTime.now().getTime();
            System.debug('@@@ END callName='+callName);
            return String.valueOf(finishTime-startTime);
        }
        catch (Exception e)
        {
            System.debug('@@@ Exception callName='+callName+ 'Exception='+e.getStackTraceString());
        }
        return null;
    }

    public static void sleep(Integer sleepSeconds) {
        Long startTS = System.currentTimeMillis();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('http://1.cuzillion.com/bin/resource.cgi?sleep=' + sleepSeconds);
        req.setMethod('GET');
        Http http = new Http();
        req.setTimeout(120000);
        HTTPResponse res = http.send(req);
        Long duration = System.currentTimeMillis() - startTS;
        System.debug('Duration: ' + duration + 'ms');
    }

}

I'm working in a Developer Edition Org. I don't understand why I do not receive any of the previous limits exception by invoking 30 simultaneous post requests with secondSleepTime=100 (I receive every httpresponse after 100 seconds).

What am I doing wrong?

  • How are you testing by calling doPost over rest or calling sleep directly in execute anonymous? – Girbot Dec 6 '18 at 8:18
  • Hi @user874253 , you can sleep apex thread in simple apex also without making callout like below. Long startTime = DateTime.now().getTime(); Long finishTime = DateTime.now().getTime(); while ((finishTime - startTime) < 6000) { finishTime = DateTime.now().getTime(); } – Amit Singh Tariyal Dec 6 '18 at 8:25
  • I want to raise one of the two exceptions because I want to understand the limits of inbound services that make callouts. @Girbot i'm testing by calling doPost over rest. – Francesco1981 Dec 6 '18 at 8:38
  • I am trying to recreate it using your endpoint but I am getting occasional internal server error/service unavailable messages. These are returning < 5 seconds, maybe that's not helping... – Girbot Dec 6 '18 at 8:53
  • @Girbot Thanks but i think that occasional internal server error/service aren't a problem for my test. What do you think? – Francesco1981 Dec 6 '18 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.