Last active
July 21, 2016 00:07
-
-
Save jdcrensh/3b56bc8bc1b3af82dd1ba5d149461302 to your computer and use it in GitHub Desktop.
[apex] Same-instance callouts provide separate transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.debug( | |
JSON.serializePretty( | |
JSON.deserializeUntyped( | |
LimitProfilingCallout.call() | |
) | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,DEBUG;WORKFLOW,INFO | |
Execute Anonymous: System.debug( | |
Execute Anonymous: JSON.serializePretty( | |
Execute Anonymous: JSON.deserializeUntyped( | |
Execute Anonymous: LimitProfilingCallout.call() | |
Execute Anonymous: ) | |
Execute Anonymous: ) | |
Execute Anonymous: ); | |
17:06:11.6 (6084087)|USER_INFO|[EXTERNAL]|00537000000IQNR|[email protected]|Pacific Standard Time|GMT-07:00 | |
17:06:11.6 (6106185)|EXECUTION_STARTED | |
17:06:11.6 (6113334)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex | |
17:06:11.6 (6502538)|SYSTEM_MODE_ENTER|false | |
17:06:11.6 (12000031)|CALLOUT_REQUEST|[41]|System.HttpRequest[Endpoint=https://na31.salesforce.com/services/apexrest/LimitProfiling, Method=POST] | |
17:06:11.6 (615485199)|CALLOUT_RESPONSE|[41]|System.HttpResponse[Status=OK, StatusCode=200] | |
17:06:11.6 (618255215)|CALLOUT_REQUEST|[44]|System.HttpRequest[Endpoint=https://na31.salesforce.com/services/apexrest/LimitProfiling, Method=POST] | |
17:06:12.135 (1135171319)|CALLOUT_RESPONSE|[44]|System.HttpResponse[Status=OK, StatusCode=200] | |
17:06:12.135 (1137783862)|CALLOUT_REQUEST|[49]|System.HttpRequest[Endpoint=https://na31.salesforce.com/services/apexrest/LimitProfiling, Method=POST] | |
17:06:12.135 (1378151799)|CALLOUT_RESPONSE|[49]|System.HttpResponse[Status=OK, StatusCode=200] | |
17:06:12.135 (1380913692)|CALLOUT_REQUEST|[52]|System.HttpRequest[Endpoint=https://na31.salesforce.com/services/apexrest/LimitProfiling, Method=POST] | |
17:06:12.135 (1635225210)|CALLOUT_RESPONSE|[52]|System.HttpResponse[Status=OK, StatusCode=200] | |
17:06:12.135 (1637869845)|CALLOUT_REQUEST|[57]|System.HttpRequest[Endpoint=https://na31.salesforce.com/services/apexrest/LimitProfiling, Method=POST] | |
17:06:13.314 (2314211352)|CALLOUT_RESPONSE|[57]|System.HttpResponse[Status=OK, StatusCode=200] | |
17:06:13.314 (2316166883)|SYSTEM_MODE_EXIT|false | |
17:06:13.314 (2316226547)|SYSTEM_MODE_ENTER|false | |
17:06:13.314 (2317109946)|SYSTEM_MODE_EXIT|false | |
17:06:13.314 (2317139631)|SYSTEM_MODE_ENTER|false | |
17:06:13.314 (2318126765)|SYSTEM_MODE_EXIT|false | |
17:06:13.314 (2318168979)|USER_DEBUG|[1]|DEBUG|[ { | |
"soql_query_limit" : 100, | |
"soql_queries" : 0, | |
"cpu_limit" : 10000, | |
"cpu" : 460 | |
}, { | |
"soql_query_limit" : 100, | |
"soql_queries" : 0, | |
"cpu_limit" : 10000, | |
"cpu" : 459 | |
}, { | |
"soql_query_limit" : 100, | |
"soql_queries" : 100, | |
"cpu_limit" : 10000, | |
"cpu" : 118 | |
}, { | |
"soql_query_limit" : 100, | |
"soql_queries" : 100, | |
"cpu_limit" : 10000, | |
"cpu" : 125 | |
}, { | |
"soql_query_limit" : 100, | |
"soql_queries" : 100, | |
"cpu_limit" : 10000, | |
"cpu" : 540 | |
} ] | |
17:06:13.320 (2320105676)|CUMULATIVE_LIMIT_USAGE | |
17:06:13.320 (2320105676)|LIMIT_USAGE_FOR_NS|(default)| | |
Number of SOQL queries: 0 out of 100 | |
Number of query rows: 0 out of 50000 | |
Number of SOSL queries: 0 out of 20 | |
Number of DML statements: 0 out of 150 | |
Number of DML rows: 0 out of 10000 | |
Maximum CPU time: 0 out of 10000 | |
Maximum heap size: 0 out of 6000000 | |
Number of callouts: 5 out of 100 | |
Number of Email Invocations: 0 out of 10 | |
Number of future calls: 0 out of 50 | |
Number of queueable jobs added to the queue: 0 out of 50 | |
Number of Mobile Apex push calls: 0 out of 10 | |
17:06:13.320 (2320105676)|CUMULATIVE_LIMIT_USAGE_END | |
17:06:13.314 (2320173460)|CODE_UNIT_FINISHED|execute_anonymous_apex | |
17:06:13.314 (2321394517)|EXECUTION_FINISHED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestResource(urlMapping = '/LimitProfiling/*') | |
global with sharing class LimitProfilingCallout { | |
@HttpPost | |
global static void callMeMaybe() { | |
RestRequest req = RestContext.request; | |
RestResponse res = RestContext.response; | |
Map<String, Object> data = (Map<String, Object>) JSON.deserializeUntyped(req.requestBody.toString()); | |
if (data.get('cpu') == true) { | |
stressTestCPU(); | |
} | |
if (data.get('soql_statements') == true) { | |
stressTestSoqlStatements(); | |
} | |
Map<String, Integer> limitData = new Map<String, Integer>(); | |
limitData.put('cpu', Limits.getCpuTime()); | |
limitData.put('soql_statements', Limits.getQueries()); | |
res.responseBody = Blob.valueOf(JSON.serialize(limitData)); | |
} | |
public static String call() { | |
Http http = new Http(); | |
HttpRequest req = new HttpRequest(); | |
req.setEndpoint('https://na31.salesforce.com/services/apexrest/LimitProfiling'); | |
req.setMethod('POST'); | |
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId()); | |
req.setHeader('Content-Type', 'application/json'); | |
req.setHeader('Content-Length', '0'); | |
List<Object> responses = new List<Object>(); | |
HttpResponse res; | |
// testing cpu | |
req.setBody('{"cpu":true}'); | |
res = http.send(req); | |
responses.add(JSON.deserializeUntyped(res.getBody())); | |
res = http.send(req); | |
responses.add(JSON.deserializeUntyped(res.getBody())); | |
// testing soql statements | |
req.setBody('{"soql_statements":true}'); | |
res = http.send(req); | |
responses.add(JSON.deserializeUntyped(res.getBody())); | |
res = http.send(req); | |
responses.add(JSON.deserializeUntyped(res.getBody())); | |
// testing both | |
req.setBody('{"cpu":true,"soql_statements":true}'); | |
res = http.send(req); | |
responses.add(JSON.deserializeUntyped(res.getBody())); | |
return JSON.serialize(responses); | |
} | |
public static void stressTestCPU() { | |
Integer n = 0; | |
for (Integer i = 0; i < 100; i++) { | |
for (Integer j = 0; j < 100; j++) { | |
for (Integer k = 0; k < 100; k++) { | |
n = i + j + k; | |
} | |
} | |
} | |
} | |
public static void stressTestSoqlStatements() { | |
for (Integer i = 0; i < 100; i++) { | |
User u = [ SELECT Id FROM User LIMIT 1 ]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment