2. @chbatey
S!*t happens when you put a
network between your classes
Christopher Batey
Freelancer / The Last Pickle
@chbatey
3. @chbatey
Who am I?
• Freelance consultant: Docker, Kubernetes,
Cassandra, JVM
• Work on a OS testing library for Cassandra
• Twitter: @chbatey
Heavily recruiting!!
10. @chbatey
Small horizontal scalable services
• Move to small services independently deployed
- Login service
- Device service
- etc
• Move to a horizontally scalable Database that can run active
active in multiple data centres
24. @chbatey
Adding an automated test
• Vagrant - launches + provisions localVMs
• Saboteur - uses tc, iptables to simulate network issues
• Wiremock - used to mock HTTP dependencies
25. @chbatey
I can write an automated test for that?
Wiremock:
•User Service
•Device Service
•Pin Service
S
a
b
o
t
e
u
r
Vagrant + Virtual box
Test meAcceptance
prime to drop traffic
reset
38. @chbatey
A simple Spring RestController
@RestController
public class Resource {
private static final Logger LOGGER = LoggerFactory.getLogger(Resource.class);
@Autowired
private ScaryDependency scaryDependency;
@RequestMapping("/scary")
public String callTheScaryDependency() {
LOGGER.info("Resource later: I wonder which thread I am on!");
return scaryDependency.getScaryString();
}
}
39. @chbatey
Scary dependency
@Component
public class ScaryDependency {
private static final Logger LOGGER = LoggerFactory.getLogger(ScaryDependency.class);
public String getScaryString() {
LOGGER.info("Scary Dependency: I wonder which thread I am on! Tomcats?”);
if (System.currentTimeMillis() % 2 == 0) {
return "Scary String";
} else {
Thread.sleep(5000)
return “Slow Scary String";
}
}
}
40. @chbatey
All on the tomcat thread
13:47:20.200 [http-8080-exec-1] INFO info.batey.examples.Resource -
Resource later: I wonder which thread I am on!
13:47:20.200 [http-8080-exec-1] INFO
info.batey.examples.ScaryDependency - Scary Dependency: I wonder which
thread I am on! Tomcats?
41. @chbatey
Scary dependency
@Component
public class ScaryDependency {
private static final Logger LOGGER = LoggerFactory.getLogger(ScaryDependency.class);
@HystrixCommand()
public String getScaryString() {
LOGGER.info("Scary Dependency: I wonder which thread I am on! Tomcats?”);
if (System.currentTimeMillis() % 2 == 0) {
return "Scary String";
} else {
Thread.sleep(5000)
return “Slow Scary String";
}
}
}
42. @chbatey
What an annotation can do...
13:51:21.513 [http-8080-exec-1] INFO info.batey.examples.Resource
- Resource later: I wonder which thread I am on!
13:51:21.614 [hystrix-ScaryDependency-1] INFO
info.batey.examples.ScaryDependency - Scary Dependency: I wonder
which thread I am on! Tomcats? :P
44. @chbatey
Drive this via requirements
• Reliable timeout
• Throttling
• Monitoring of failures / successes
45. @chbatey
Timeouts take home
• You can’t use network level timeouts for SLAs
• Test your SLAs - if someone says you can’t, hit them with a
stick
• Scary things happen without network issues
51. @chbatey
Don’t try if you can’t succeed
• Executor Unbounded queues :(
- newFixedThreadPool
- newSingleThreadExecutor
- newThreadCachedThreadPool
• Bound your queues and threads
• Fail quickly when the queue / maxPoolSize is met
• Know your drivers
52. @chbatey
This is a functional requirement
• Set the timeout very high
• Use Wiremock to add a large delay to the requests
• Set queue size and thread pool size to 1
• Send in 2 requests to use the thread and fill the queue
• What happens on the 3rd request?