SlideShare a Scribd company logo
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
AWS Java SDK @ scale
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."
Ad

More Related Content

What's hot (20)

Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
Tomasz Kowalczewski
 
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
Islam Sharabash
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
Tomáš Kypta
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
Tomáš 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.js
Forrest 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 2016
Frank Lyaruu
 
Ice mini guide
Ice mini guideIce mini guide
Ice mini guide
Ady Liu
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
Dustin Graham
 
RxJava Applied
RxJava AppliedRxJava Applied
RxJava Applied
Igor Lozynskyi
 
Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
David Gómez García
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
Tomáš Kypta
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
Brainhub
 
Jafka guide
Jafka guideJafka guide
Jafka guide
Ady 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 Android
Egor Andreevich
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac plugin
Oleksandr Radchykov
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
Troy Miles
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
SmartLogic
 
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
Alex Payne
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
Savvycom Savvycom
 
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
Islam Sharabash
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
Tomáš Kypta
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
Tomáš 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.js
Forrest 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 2016
Frank Lyaruu
 
Ice mini guide
Ice mini guideIce mini guide
Ice mini guide
Ady Liu
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
Tomáš Kypta
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
Brainhub
 
Jafka guide
Jafka guideJafka guide
Jafka guide
Ady 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 Android
Egor Andreevich
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac plugin
Oleksandr Radchykov
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
Troy Miles
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
SmartLogic
 
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
Alex Payne
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
Savvycom Savvycom
 

Viewers also liked (16)

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 2
John Johari
 
Microsoft/s1190206
Microsoft/s1190206Microsoft/s1190206
Microsoft/s1190206
s1190206
 
Www.kutub.info 5727
Www.kutub.info 5727Www.kutub.info 5727
Www.kutub.info 5727
Adel Totott
 
Br fra-v1.2
Br fra-v1.2Br fra-v1.2
Br fra-v1.2
Bernd Rodler
 
Social groups evalutation
Social groups evalutationSocial groups evalutation
Social groups evalutation
xhollyjohnson
 
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
Gladimar 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 McGonigal
Burning Eye
 
Japanorama (2)
Japanorama (2)Japanorama (2)
Japanorama (2)
culturelestudies2012
 
TKConf Сетевые орг. структуры
TKConf Сетевые орг. структурыTKConf Сетевые орг. структуры
TKConf Сетевые орг. структуры
Vladimir Kalenov
 
мобильные приложения для бизнеса
мобильные приложения для бизнесамобильные приложения для бизнеса
мобильные приложения для бизнеса
Alexey Zakharov
 
Schoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijdSchoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijd
Steven 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
 
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 2
John Johari
 
Microsoft/s1190206
Microsoft/s1190206Microsoft/s1190206
Microsoft/s1190206
s1190206
 
Www.kutub.info 5727
Www.kutub.info 5727Www.kutub.info 5727
Www.kutub.info 5727
Adel Totott
 
Social groups evalutation
Social groups evalutationSocial groups evalutation
Social groups evalutation
xhollyjohnson
 
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
Gladimar 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 McGonigal
Burning Eye
 
TKConf Сетевые орг. структуры
TKConf Сетевые орг. структурыTKConf Сетевые орг. структуры
TKConf Сетевые орг. структуры
Vladimir Kalenov
 
мобильные приложения для бизнеса
мобильные приложения для бизнесамобильные приложения для бизнеса
мобильные приложения для бизнеса
Alexey Zakharov
 
Schoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijdSchoolfeest 2015 fotowedstrijd
Schoolfeest 2015 fotowedstrijd
Steven 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
 
Ad

Similar to AWS Java SDK @ scale (20)

Hands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud DevelopersHands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud Developers
Meetu Maltiar
 
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
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 functions
Matt Lavin
 
CloudStack S3
CloudStack S3CloudStack S3
CloudStack S3
Sebastien Goasguen
 
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
confluent
 
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
Dropsolid
 
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
AOE
 
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
oazabir
 
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
Daniel Ballinger
 
A tale of application development
A tale of application developmentA tale of application development
A tale of application development
Nicolas Corrarello
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jp
Satoshi 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) Family
Ben 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 Clients
Salesforce Developers
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
GWTcon
 
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
Danilo Poccia
 
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
 
Jclouds Intro
Jclouds IntroJclouds Intro
Jclouds Intro
guesta31f61
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL Azure
Ike Ellis
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
Ivanti
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
Christian Melchior
 
Hands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud DevelopersHands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud Developers
Meetu Maltiar
 
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
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 functions
Matt Lavin
 
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
confluent
 
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
Dropsolid
 
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
AOE
 
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
oazabir
 
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
Daniel Ballinger
 
A tale of application development
A tale of application developmentA tale of application development
A tale of application development
Nicolas Corrarello
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jp
Satoshi 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) Family
Ben 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 Clients
Salesforce Developers
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
GWTcon
 
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
Danilo Poccia
 
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
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL Azure
Ike Ellis
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
Ivanti
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
Christian Melchior
 
Ad

More from Tomasz Kowalczewski (12)

[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
Tomasz Kowalczewski
 
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
Tomasz Kowalczewski
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
Tomasz Kowalczewski
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
Tomasz Kowalczewski
 
Is writing performant code too expensive?
Is writing performant code too expensive?Is writing performant code too expensive?
Is writing performant code too expensive?
Tomasz Kowalczewski
 
Everybody Lies
Everybody LiesEverybody Lies
Everybody Lies
Tomasz Kowalczewski
 
Measure to fail
Measure to failMeasure to fail
Measure to fail
Tomasz Kowalczewski
 
Reactive Java at JDD 2014
Reactive Java at JDD 2014Reactive Java at JDD 2014
Reactive Java at JDD 2014
Tomasz Kowalczewski
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
Tomasz Kowalczewski
 
Introduction to Reactive Java
Introduction to Reactive JavaIntroduction to Reactive Java
Introduction to Reactive Java
Tomasz Kowalczewski
 
Java 8 jest tuż za rogiem
Java 8 jest tuż za rogiemJava 8 jest tuż za rogiem
Java 8 jest tuż za rogiem
Tomasz Kowalczewski
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
Tomasz Kowalczewski
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
Tomasz Kowalczewski
 
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
Tomasz Kowalczewski
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
Tomasz Kowalczewski
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
Tomasz Kowalczewski
 
Is writing performant code too expensive?
Is writing performant code too expensive?Is writing performant code too expensive?
Is writing performant code too expensive?
Tomasz Kowalczewski
 

Recently uploaded (20)

Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 

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
  • 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."