We use JMeter to stress test our Salesforce API when we want to test how code updates behave with production-level traffic.
- Follow the instructions on the JMeter site to download and install JMeter
- Verify that you can run the JMeter GUI:
- cd into the
apache-jmeter-5.2.1
directory whereve you've unzipped it - run
./bin/jmeter
- Using e.g. Postman, setup a POST request to the ADMIN_TOKEN_URL (https://sfhousing--full.my.salesforce.com/services/oauth2/token)
- Update the Body to have the following keys (values are in the .env file):
grant_type:password
client_id:{{SALESFORCE_CLIENT_ID}}
client_secret:{{SALESFORCE_CLIENT_SECRET}}
username:{{SALESFORCE_USERNAME}}
password:{{SALESFORCE_PASSWORD}}{{SALESFORCE_SECURITY_TOKEN}}
- Send the request
- The auth_token should be included in the response body
- Open the Sharing_Stress_Test_Plan.jmx file in the JMeter GUI
- cd into the
apache-jmeter-5.2.1
directory where you unzipped the file - Export your oauth token you fetched into an env var:
export OAUTH_TOKEN='[auth_token from salesforce]'
- Run
./bin/jmeter.sh -n -t [Path to sf-dahlia-web]/load_testing/Sharing_Stress_Test_Plan.jmx -l stress_test_results/summary.jtl -Joauth_token=$OAUTH_TOKEN
- Open up the Sharing_Stress_Test_Plan.jmx file in the JMeter GUI
- Make edits as necessary
- To test edits, update the thread count and loop count under "Stess Test Application Submission" to be 1-2 each, then run using the green play button. This is becuase the GUI should only be used for small numbers of requests. If you are running via the GUI you may need to manually enter the oauth token under "HTTP Header Manager" > "Authorization"
- When committing updates, make sure that you do not commit the auth_token with your changes.
- To update the total number of requests being made, update the "Number of Threads" and "Loop Count" under the top level "Stress Test Application Submission"
- To update the request/minute througput, update the "Target Throughput" under the "Constant Throughput Timer". This number controls the total request throughput, so to find the equivalent for applications submitted / minute, divide by 4.
- To update the base URL for requests, update the url under "Server Name or IP" under "HTTP Requests Defaults"
- Open the DAHLIA-Full-Listing-Images.jmx file in the JMeter GUI
- Run the test and view the Graph Results