Created
June 27, 2014 17:15
-
-
Save drautb/64af8fa3c09383b9fd3f to your computer and use it in GitHub Desktop.
Sandbox to stress AWS SDK. The SDK will automatically retry requests if your hitting the API too frequently, but only 3 times by default. This sometimes is insufficient.
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
import java.util.Date; | |
import java.util.Map; | |
import java.lang.Thread; | |
import com.amazonaws.ClientConfiguration; | |
import com.amazonaws.auth.BasicAWSCredentials; | |
import com.amazonaws.regions.Region; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.cloudformation.AmazonCloudFormation; | |
import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; | |
import com.amazonaws.retry.RetryPolicy; | |
public class AWSSDKStressTest { | |
private static final int SOCKET_TIMEOUT_IN_MILLIS = 120000; | |
private static final int MAX_ERROR_RETRIES = 10; | |
private static final String AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID"; | |
private static final String AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"; | |
public static void main(String[] args) { | |
int t = 10; | |
System.out.println("Going to spawn " + t + " threads..."); | |
for (int i=0; i<t; i++) { | |
Thread thread = new Thread() { | |
public void run() { | |
String accessKeyId = System.getenv().get(AWS_ACCESS_KEY_ID); | |
String secretKey = System.getenv().get(AWS_SECRET_ACCESS_KEY); | |
BasicAWSCredentials creds = new BasicAWSCredentials(accessKeyId, secretKey); | |
ClientConfiguration config = new ClientConfiguration().withSocketTimeout(SOCKET_TIMEOUT_IN_MILLIS).withMaxErrorRetry(MAX_ERROR_RETRIES); | |
AmazonCloudFormation client = new AmazonCloudFormationClient(creds, config); | |
client.setRegion(Region.getRegion(Regions.fromName("us-east-1"))); | |
int n = 5; | |
System.out.println("Going to call listStacks " + n + " times..."); | |
for (int j=0; j<n; j++) { | |
System.out.println("[" + getName() + "] Call #" + (j+1) + " @" + new Date()); | |
client.listStacks(); | |
} | |
System.out.println("[" + getName() + "] Done."); | |
} | |
}; | |
thread.start(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment