SlideShare a Scribd company logo
1 of 27
Download to read offline
A W S J AVA S D K @ S C A L E
B A S E D M O S T LY O N E X P E R I E N C E S W I T H S 3
image source: http://xkcd.com/
C R E D E N T I A L S
O U R
E N D P O I N T S
• REST API for everyone
• Great documentation
• http://aws.amazon.com/
documentation/
A W S J AVA S D K
• One monolithic jar before 1.9.0
• Currently split into ~48 smaller modules dedicated to individual
Amazon services
• All depend on aws-java-sdk-core module
• Other runtime dependencies:
• commons-logging
• apache http client (4.3.4)
• joda time
C R E D E N T I A L S
• Manually provide accessKey and secretKey (generated
by IAM)
• Manual key management
• No automatic rotation
• Leaked keys will loose you serious $$$
new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
C R E D E N T I A L S
“I only had S3 keys on my GitHub and they where gone within 5 minutes!
Turns out through the S3 API you can actually spin up EC2 instances, and my key had
been spotted by a bot that continually searches GitHub for API keys. Amazon AWS
customer support informed me this happens a lot recently, hackers have created an
algorithm that searches GitHub 24 hours per day for API keys. Once it finds one it spins
up max instances of EC2 servers to farm itself bitcoins.
Boom! A $2375 bill in the morning.”
http://www.devfactor.net/2014/12/30/2375-amazon-mistake/
C R E D E N T I A L S
• Use credentials provider
• Default behaviour when zero argument constructor is invoked
• EnvironmentVariableCredentialsProvider

SystemPropertiesCredentialsProvider

ProfileCredentialsProvider

InstanceProfileCredentialsProvider
• All but last one share security problems with manual access/
secret keys management
new AmazonS3Client();
C R E D E N T I A L S
• Use InstanceProfileCredentialsProvider
• Needs IAM role of the server to be configured with permissions
needed by the service using this provider.
• Calls EC2 Instance Metadata Service to get current security
credentials.
• http://169.254.169.254/latest/meta-data/iam/security-credentials/
• Automatic management and rotation of keys.
• Stored only in memory of calling process
C R E D E N T I A L S
• Use InstanceProfileCredentialsProvider
• Credentials are reloaded under lock which may cause
latency spikes (every hour).
• Instantiate with refreshCredentialsAsync == true
• Problems when starting on developers machines
• Use AdRoll’s hologram to create fake environment locally
• https://github.com/AdRoll/hologram
B U I LT I N M O N I T O R I N G
amazonS3Client.addRequestHandler(new RequestHandler2() {

@Override

public void beforeRequest(Request<?> request) {



}



@Override

public void afterResponse(Request<?> request, Response<?> response) {

request.getAWSRequestMetrics()...

}



@Override

public void afterError(Request<?> request, Response<?> response, Exception e) {



}

});
B U I LT I N M O N I T O R I N G
AmazonS3Client amazonS3 = new AmazonS3Client(
new StaticCredentialsProvider(credentials),
new ClientConfiguration(),
new RequestMetricCollector() {

@Override

public void collectMetrics(Request<?> request, Response<?> response) {


}

}
);
T E S T I N G W I T H S 3
• Use buckets located close to testing site
• Use fake S3 process:
• https://github.com/jubos/fake-s3
• https://github.com/tkowalcz/fake-s3
• same thing but with few bug fixes
• Not scalable enough
• Write your own :(
• Not that hard
//lookout for issue 414
amazonS3.setEndpoint(“http://localhost...");
S C A RY S T U F F
• #333 SDK can't list bucket nor delete S3 object with characters in
range [0x00 - 0x1F] #333
• According to the S3 objects naming scheme, [0x00 - 0x1F] are
valid characters for the S3 object. However, it's not possible to list
bucket with such objects using the SDK (XML parser chokes on
them) and also, they can't be deleted thru multi objects delete
(also XML failure). What is interesting, download works just fine.
• #797 S3 delete_objects silently fails with object names containing
characters in the 0x00-0x1F range
• Bulk delete over 1024 objects will fail with unrelated exception
“ A S Y N C H R O N O U S ” V E R S I O N S
• There is no truly asynchronous mode in AWS SDK
• Async versions of clients use synchronous blocking
http calls but wrap them in a thread pool
• S3 has TransferManager (we have no experience here)
B A S I C S 3 P E R F O R M A N C E T I P S
• Pseudo random key prefix allows splitting files among
S3 “partitions” evenly
• Listing is usually the bottleneck. Cache list results.
• Or write your own microservice to eliminate lists
S D K P E R F O R M A N C E
• Creates tons of short lived objects
• Many locks guarding internal state
• Profiled with Java Mission Control (if it does not crash)
• Or Yourkit
• Then test on production data
public XmlResponsesSaxParser() throws AmazonClientException {

// Ensure we can load the XML Reader.

try {

xr = XMLReaderFactory.createXMLReader();

} catch (SAXException e) {

throw new AmazonClientException("Couldn't initialize a SAX driver to create
an XMLReader", e);

}

}

@Override

protected final CloseableHttpResponse doExecute(final HttpHost target, final
HttpRequest request,

final HttpContext context)

throws IOException, ClientProtocolException {



Args.notNull(request, "HTTP request");

// a null target may be acceptable, this depends on the route planner

// a null context is acceptable, default context created below



HttpContext execContext = null;

RequestDirector director = null;

HttpRoutePlanner routePlanner = null;

ConnectionBackoffStrategy connectionBackoffStrategy = null;

BackoffManager backoffManager = null;



// Initialize the request execution context making copies of

// all shared objects that are potentially threading unsafe.

synchronized (this) {
public synchronized final ClientConnectionManager getConnectionManager() {

if (connManager == null) {

connManager = createClientConnectionManager();

}

return connManager;

}





public synchronized final HttpRequestExecutor getRequestExecutor() {

if (requestExec == null) {

requestExec = createRequestExecutor();

}

return requestExec;

}





public synchronized final AuthSchemeRegistry getAuthSchemes() {

if (supportedAuthSchemes == null) {

supportedAuthSchemes = createAuthSchemeRegistry();

}

return supportedAuthSchemes;

}



public synchronized void setAuthSchemes(final AuthSchemeRegistry registry) {

supportedAuthSchemes = registry;

}



public synchronized final ConnectionBackoffStrategy getConnectionBackoffStrategy() {

return connectionBackoffStrategy;

}
O L D A PA C H E H T T P C L I E N T ( 4 . 3 . 4 )
• Riddled with locks
• Reusing same client can save resources but at cost of performance
• different code paths may not target same sites
• open sockets are not that costly
• better use many client instances (e.g. per-thread)
• Make sure number of threads using one client instance it is less than maximum
number of connections in its pool
• severe contention on returning connections to pool
• recent versions got better
B A S I C C O N F I G U R AT I O N
<bean id=“...” class="com.amazonaws.services.s3.AmazonS3Client" scope="prototype">

<constructor-arg>

<bean class="com.amazonaws.ClientConfiguration">

<property name="maxConnections"
value="#{T(Integer).parseInt('${storage.readingThreads}') * 2}”/>


<property name="protocol" value="HTTP"/>

</bean>

</constructor-arg>

</bean>
C L I E N T P O O L
<bean id="poolTargetSource" class="pl.codewise.voluum.util.AmazonS3ClientPool">

<property name="targetBeanName" value="amazonS3Client"/>

<property name="maxSize" value="10"/>

</bean>



<bean id="amazonS3Client" class="org.springframework.aop.framework.ProxyFactoryBean"
primary="true">

<property name="targetSource" ref="poolTargetSource"/>

<property name="interfaces">

<list>

<value>com.amazonaws.services.s3.AmazonS3</value>

</list>

</property>

</bean>
int index = ThreadLocalRandom.current().nextInt(getMaxSize());

return clients[index];
W H AT T O D O W I T H T H I S ?
• Hardcore approach (classpath overrides of following classes)
• Our own AbstractAWSSigner that uses third party, lock
free HmacSHA1 signing algorithm
• ResponseMetadataCache without locks (send metadata
to /dev/null)
• AmazonHttpClient to remove call to System.getProperty
• DateUtils using joda time (now fixed in SDK itself)
D s t a t o u t p u t . U s e r m o d e c p u u s a g e
m o s t l y re l a t e d t o d a t a p ro c e s s i n g .
P E R F O R M A N C E A C H I E V E D
CPU (user, system, idle) Network transfer (IN/OUT) IRQ/CNTX
O P T I M I S AT I O N S R E S U LT
com.amazonaws.services.s3.model.AmazonS3Exception:
Please reduce your request rate.
(Service: Amazon S3; Status Code: 503; Error Code: SlowDown)
– H E N RY P E T R O S K I
"The most amazing achievement of the computer
software industry is its continuing cancellation of
the steady and staggering gains made by the
computer hardware industry."

More Related Content

What's hot

Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerIslam Sharabash
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
CLS & asyncListener: asynchronous observability for Node.js
CLS & asyncListener: asynchronous observability for Node.jsCLS & asyncListener: asynchronous observability for Node.js
CLS & asyncListener: asynchronous observability for Node.jsForrest Norvell
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016Frank Lyaruu
 
Ice mini guide
Ice mini guideIce mini guide
Ice mini guideAdy Liu
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
Jafka guide
Jafka guideJafka guide
Jafka guideAdy Liu
 
Intro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich AndroidIntro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich AndroidEgor Andreevich
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac pluginOleksandr Radchykov
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive CocoaSmartLogic
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroidSavvycom Savvycom
 

What's hot (20)

Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
CLS & asyncListener: asynchronous observability for Node.js
CLS & asyncListener: asynchronous observability for Node.jsCLS & asyncListener: asynchronous observability for Node.js
CLS & asyncListener: asynchronous observability for Node.js
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Ice mini guide
Ice mini guideIce mini guide
Ice mini guide
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
 
RxJava Applied
RxJava AppliedRxJava Applied
RxJava Applied
 
Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Jafka guide
Jafka guideJafka guide
Jafka guide
 
Intro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich AndroidIntro to RxJava/RxAndroid - GDG Munich Android
Intro to RxJava/RxAndroid - GDG Munich Android
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac plugin
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 

Viewers also liked

Deep dive reactive java (DevoxxPl)
Deep dive reactive java (DevoxxPl)Deep dive reactive java (DevoxxPl)
Deep dive reactive java (DevoxxPl)Tomasz Kowalczewski
 
Empirical stands of business succesion among african owned business africa 2
Empirical stands of business succesion among african owned business africa 2Empirical stands of business succesion among african owned business africa 2
Empirical stands of business succesion among african owned business africa 2John Johari
 
Microsoft/s1190206
Microsoft/s1190206Microsoft/s1190206
Microsoft/s1190206s1190206
 
Www.kutub.info 5727
Www.kutub.info 5727Www.kutub.info 5727
Www.kutub.info 5727Adel Totott
 
Social groups evalutation
Social groups evalutationSocial groups evalutation
Social groups evalutationxhollyjohnson
 
First steps through america soc stud 5th
First steps through america   soc stud 5thFirst steps through america   soc stud 5th
First steps through america soc stud 5thGladimar Marín
 
The Failed Idealist's Guide to the Tatty Truth by Fergus McGonigal
The Failed Idealist's Guide to the Tatty Truth by Fergus McGonigalThe Failed Idealist's Guide to the Tatty Truth by Fergus McGonigal
The Failed Idealist's Guide to the Tatty Truth by Fergus McGonigalBurning Eye
 
TKConf Сетевые орг. структуры
TKConf Сетевые орг. структурыTKConf Сетевые орг. структуры
TKConf Сетевые орг. структурыVladimir Kalenov
 
мобильные приложения для бизнеса
мобильные приложения для бизнесамобильные приложения для бизнеса
мобильные приложения для бизнесаAlexey Zakharov
 
Schoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijdSchoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijdSteven Verleysen
 
Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...
Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...
Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...Saba Software
 

Viewers also liked (16)

Deep dive reactive java (DevoxxPl)
Deep dive reactive java (DevoxxPl)Deep dive reactive java (DevoxxPl)
Deep dive reactive java (DevoxxPl)
 
Emd
EmdEmd
Emd
 
Empirical stands of business succesion among african owned business africa 2
Empirical stands of business succesion among african owned business africa 2Empirical stands of business succesion among african owned business africa 2
Empirical stands of business succesion among african owned business africa 2
 
Presentazione report 2011
Presentazione report 2011Presentazione report 2011
Presentazione report 2011
 
Microsoft/s1190206
Microsoft/s1190206Microsoft/s1190206
Microsoft/s1190206
 
Www.kutub.info 5727
Www.kutub.info 5727Www.kutub.info 5727
Www.kutub.info 5727
 
Br fra-v1.2
Br fra-v1.2Br fra-v1.2
Br fra-v1.2
 
Social groups evalutation
Social groups evalutationSocial groups evalutation
Social groups evalutation
 
First steps through america soc stud 5th
First steps through america   soc stud 5thFirst steps through america   soc stud 5th
First steps through america soc stud 5th
 
The Failed Idealist's Guide to the Tatty Truth by Fergus McGonigal
The Failed Idealist's Guide to the Tatty Truth by Fergus McGonigalThe Failed Idealist's Guide to the Tatty Truth by Fergus McGonigal
The Failed Idealist's Guide to the Tatty Truth by Fergus McGonigal
 
Japanorama (2)
Japanorama (2)Japanorama (2)
Japanorama (2)
 
TKConf Сетевые орг. структуры
TKConf Сетевые орг. структурыTKConf Сетевые орг. структуры
TKConf Сетевые орг. структуры
 
мобильные приложения для бизнеса
мобильные приложения для бизнесамобильные приложения для бизнеса
мобильные приложения для бизнеса
 
Manajemen kesehatan2
Manajemen kesehatan2Manajemen kesehatan2
Manajemen kesehatan2
 
Schoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijdSchoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijd
 
Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...
Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...
Guitar Center: Integrating Social and Collaborative Learning to Create a Cult...
 

Similar to AWS Java SDK @ scale

윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션Amazon Web Services Korea
 
Node Summit 2018 - Optimize your Lambda functions
Node Summit 2018 - Optimize your Lambda functionsNode Summit 2018 - Optimize your Lambda functions
Node Summit 2018 - Optimize your Lambda functionsMatt Lavin
 
Lab Manual Combaring Redis with Relational
Lab Manual Combaring Redis with RelationalLab Manual Combaring Redis with Relational
Lab Manual Combaring Redis with RelationalAmazon Web Services
 
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQLKafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQLconfluent
 
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and moreScaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and moreDropsolid
 
Immutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaImmutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaAOE
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsDaniel Ballinger
 
Hands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with RelationalHands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with RelationalAmazon Web Services
 
A tale of application development
A tale of application developmentA tale of application development
A tale of application developmentNicolas Corrarello
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jpSatoshi Konno
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyBen Hall
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsSalesforce Developers
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDanilo Poccia
 
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)Amazon Web Services
 
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...Andrey Devyatkin
 

Similar to AWS Java SDK @ scale (20)

윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
 
Node Summit 2018 - Optimize your Lambda functions
Node Summit 2018 - Optimize your Lambda functionsNode Summit 2018 - Optimize your Lambda functions
Node Summit 2018 - Optimize your Lambda functions
 
CloudStack S3
CloudStack S3CloudStack S3
CloudStack S3
 
Lab Manual Combaring Redis with Relational
Lab Manual Combaring Redis with RelationalLab Manual Combaring Redis with Relational
Lab Manual Combaring Redis with Relational
 
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQLKafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
 
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and moreScaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
 
Immutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaImmutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS Lambda
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
 
Hands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with RelationalHands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with Relational
 
A tale of application development
A tale of application developmentA tale of application development
A tale of application development
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jp
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
 
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
 
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
 
Jclouds Intro
Jclouds IntroJclouds Intro
Jclouds Intro
 
Amazon ECS Deep Dive
Amazon ECS Deep DiveAmazon ECS Deep Dive
Amazon ECS Deep Dive
 

More from Tomasz Kowalczewski

More from Tomasz Kowalczewski (11)

How I learned to stop worrying and love the dark silicon apocalypse.pdf
How I learned to stop worrying and love the dark silicon apocalypse.pdfHow I learned to stop worrying and love the dark silicon apocalypse.pdf
How I learned to stop worrying and love the dark silicon apocalypse.pdf
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
Is writing performant code too expensive?
Is writing performant code too expensive?Is writing performant code too expensive?
Is writing performant code too expensive?
 
Everybody Lies
Everybody LiesEverybody Lies
Everybody Lies
 
Measure to fail
Measure to failMeasure to fail
Measure to fail
 
Reactive Java at JDD 2014
Reactive Java at JDD 2014Reactive Java at JDD 2014
Reactive Java at JDD 2014
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
 
Introduction to Reactive Java
Introduction to Reactive JavaIntroduction to Reactive Java
Introduction to Reactive Java
 
Java 8 jest tuż za rogiem
Java 8 jest tuż za rogiemJava 8 jest tuż za rogiem
Java 8 jest tuż za rogiem
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 

Recently uploaded (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 

AWS Java SDK @ scale

  • 1. A W S J AVA S D K @ S C A L E B A S E D M O S T LY O N E X P E R I E N C E S W I T H S 3 image source: http://xkcd.com/
  • 2. C R E D E N T I A L S O U R
  • 3. E N D P O I N T S • REST API for everyone • Great documentation • http://aws.amazon.com/ documentation/
  • 4. A W S J AVA S D K • One monolithic jar before 1.9.0 • Currently split into ~48 smaller modules dedicated to individual Amazon services • All depend on aws-java-sdk-core module • Other runtime dependencies: • commons-logging • apache http client (4.3.4) • joda time
  • 5. C R E D E N T I A L S • Manually provide accessKey and secretKey (generated by IAM) • Manual key management • No automatic rotation • Leaked keys will loose you serious $$$ new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
  • 6. C R E D E N T I A L S “I only had S3 keys on my GitHub and they where gone within 5 minutes! Turns out through the S3 API you can actually spin up EC2 instances, and my key had been spotted by a bot that continually searches GitHub for API keys. Amazon AWS customer support informed me this happens a lot recently, hackers have created an algorithm that searches GitHub 24 hours per day for API keys. Once it finds one it spins up max instances of EC2 servers to farm itself bitcoins. Boom! A $2375 bill in the morning.” http://www.devfactor.net/2014/12/30/2375-amazon-mistake/
  • 7. C R E D E N T I A L S • Use credentials provider • Default behaviour when zero argument constructor is invoked • EnvironmentVariableCredentialsProvider
 SystemPropertiesCredentialsProvider
 ProfileCredentialsProvider
 InstanceProfileCredentialsProvider • All but last one share security problems with manual access/ secret keys management new AmazonS3Client();
  • 8. C R E D E N T I A L S • Use InstanceProfileCredentialsProvider • Needs IAM role of the server to be configured with permissions needed by the service using this provider. • Calls EC2 Instance Metadata Service to get current security credentials. • http://169.254.169.254/latest/meta-data/iam/security-credentials/ • Automatic management and rotation of keys. • Stored only in memory of calling process
  • 9. C R E D E N T I A L S • Use InstanceProfileCredentialsProvider • Credentials are reloaded under lock which may cause latency spikes (every hour). • Instantiate with refreshCredentialsAsync == true • Problems when starting on developers machines • Use AdRoll’s hologram to create fake environment locally • https://github.com/AdRoll/hologram
  • 10. B U I LT I N M O N I T O R I N G amazonS3Client.addRequestHandler(new RequestHandler2() {
 @Override
 public void beforeRequest(Request<?> request) {
 
 }
 
 @Override
 public void afterResponse(Request<?> request, Response<?> response) {
 request.getAWSRequestMetrics()...
 }
 
 @Override
 public void afterError(Request<?> request, Response<?> response, Exception e) {
 
 }
 });
  • 11. B U I LT I N M O N I T O R I N G AmazonS3Client amazonS3 = new AmazonS3Client( new StaticCredentialsProvider(credentials), new ClientConfiguration(), new RequestMetricCollector() {
 @Override
 public void collectMetrics(Request<?> request, Response<?> response) { 
 }
 } );
  • 12. T E S T I N G W I T H S 3 • Use buckets located close to testing site • Use fake S3 process: • https://github.com/jubos/fake-s3 • https://github.com/tkowalcz/fake-s3 • same thing but with few bug fixes • Not scalable enough • Write your own :( • Not that hard //lookout for issue 414 amazonS3.setEndpoint(“http://localhost...");
  • 13. S C A RY S T U F F • #333 SDK can't list bucket nor delete S3 object with characters in range [0x00 - 0x1F] #333 • According to the S3 objects naming scheme, [0x00 - 0x1F] are valid characters for the S3 object. However, it's not possible to list bucket with such objects using the SDK (XML parser chokes on them) and also, they can't be deleted thru multi objects delete (also XML failure). What is interesting, download works just fine. • #797 S3 delete_objects silently fails with object names containing characters in the 0x00-0x1F range • Bulk delete over 1024 objects will fail with unrelated exception
  • 14. “ A S Y N C H R O N O U S ” V E R S I O N S • There is no truly asynchronous mode in AWS SDK • Async versions of clients use synchronous blocking http calls but wrap them in a thread pool • S3 has TransferManager (we have no experience here)
  • 15. B A S I C S 3 P E R F O R M A N C E T I P S • Pseudo random key prefix allows splitting files among S3 “partitions” evenly • Listing is usually the bottleneck. Cache list results. • Or write your own microservice to eliminate lists
  • 16. S D K P E R F O R M A N C E • Creates tons of short lived objects • Many locks guarding internal state • Profiled with Java Mission Control (if it does not crash) • Or Yourkit • Then test on production data
  • 17.
  • 18. public XmlResponsesSaxParser() throws AmazonClientException {
 // Ensure we can load the XML Reader.
 try {
 xr = XMLReaderFactory.createXMLReader();
 } catch (SAXException e) {
 throw new AmazonClientException("Couldn't initialize a SAX driver to create an XMLReader", e);
 }
 }

  • 19. @Override
 protected final CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request,
 final HttpContext context)
 throws IOException, ClientProtocolException {
 
 Args.notNull(request, "HTTP request");
 // a null target may be acceptable, this depends on the route planner
 // a null context is acceptable, default context created below
 
 HttpContext execContext = null;
 RequestDirector director = null;
 HttpRoutePlanner routePlanner = null;
 ConnectionBackoffStrategy connectionBackoffStrategy = null;
 BackoffManager backoffManager = null;
 
 // Initialize the request execution context making copies of
 // all shared objects that are potentially threading unsafe.
 synchronized (this) {
  • 20. public synchronized final ClientConnectionManager getConnectionManager() {
 if (connManager == null) {
 connManager = createClientConnectionManager();
 }
 return connManager;
 }
 
 
 public synchronized final HttpRequestExecutor getRequestExecutor() {
 if (requestExec == null) {
 requestExec = createRequestExecutor();
 }
 return requestExec;
 }
 
 
 public synchronized final AuthSchemeRegistry getAuthSchemes() {
 if (supportedAuthSchemes == null) {
 supportedAuthSchemes = createAuthSchemeRegistry();
 }
 return supportedAuthSchemes;
 }
 
 public synchronized void setAuthSchemes(final AuthSchemeRegistry registry) {
 supportedAuthSchemes = registry;
 }
 
 public synchronized final ConnectionBackoffStrategy getConnectionBackoffStrategy() {
 return connectionBackoffStrategy;
 }
  • 21. O L D A PA C H E H T T P C L I E N T ( 4 . 3 . 4 ) • Riddled with locks • Reusing same client can save resources but at cost of performance • different code paths may not target same sites • open sockets are not that costly • better use many client instances (e.g. per-thread) • Make sure number of threads using one client instance it is less than maximum number of connections in its pool • severe contention on returning connections to pool • recent versions got better
  • 22. B A S I C C O N F I G U R AT I O N <bean id=“...” class="com.amazonaws.services.s3.AmazonS3Client" scope="prototype">
 <constructor-arg>
 <bean class="com.amazonaws.ClientConfiguration">
 <property name="maxConnections" value="#{T(Integer).parseInt('${storage.readingThreads}') * 2}”/> 
 <property name="protocol" value="HTTP"/>
 </bean>
 </constructor-arg>
 </bean>
  • 23. C L I E N T P O O L <bean id="poolTargetSource" class="pl.codewise.voluum.util.AmazonS3ClientPool">
 <property name="targetBeanName" value="amazonS3Client"/>
 <property name="maxSize" value="10"/>
 </bean>
 
 <bean id="amazonS3Client" class="org.springframework.aop.framework.ProxyFactoryBean" primary="true">
 <property name="targetSource" ref="poolTargetSource"/>
 <property name="interfaces">
 <list>
 <value>com.amazonaws.services.s3.AmazonS3</value>
 </list>
 </property>
 </bean> int index = ThreadLocalRandom.current().nextInt(getMaxSize());
 return clients[index];
  • 24. W H AT T O D O W I T H T H I S ? • Hardcore approach (classpath overrides of following classes) • Our own AbstractAWSSigner that uses third party, lock free HmacSHA1 signing algorithm • ResponseMetadataCache without locks (send metadata to /dev/null) • AmazonHttpClient to remove call to System.getProperty • DateUtils using joda time (now fixed in SDK itself)
  • 25. D s t a t o u t p u t . U s e r m o d e c p u u s a g e m o s t l y re l a t e d t o d a t a p ro c e s s i n g . P E R F O R M A N C E A C H I E V E D CPU (user, system, idle) Network transfer (IN/OUT) IRQ/CNTX
  • 26. O P T I M I S AT I O N S R E S U LT com.amazonaws.services.s3.model.AmazonS3Exception: Please reduce your request rate. (Service: Amazon S3; Status Code: 503; Error Code: SlowDown)
  • 27. – H E N RY P E T R O S K I "The most amazing achievement of the computer software industry is its continuing cancellation of the steady and staggering gains made by the computer hardware industry."