5. Keeping up with Elasticsearch
Elasticsearch is moving fast and developers are upgrading:
● Upgrade to Elasticsearch 6.7.x
● Deprecate the Elasticsearch native transport support
(will be removed in future Elasticsearch versions / Spring Data release trains)
● Deprecate the Jest HTTP client support
● Improving the support of RestClient + RestHighLevelClient
● Spring Data Repository support for RestHighLevelClient
● Health Indicators, configuration properties
6. RestHighLevelClient auto-configuration
@Service
public class SearchService {
private final RestHighLevelClient client;
public SearchService(RestHighLevelClient client) {
this.client = client;
}
public SearchHit[] search() throws IOException {
SearchRequest searchRequest = new SearchRequest("tweets");
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.termQuery("hashtags", "pivotalparis"));
searchRequest.source(sourceBuilder);
return this.client.search(searchRequest, RequestOptions.DEFAULT).getHits().getHits();
}
}
7. And more!
The Spring Data team worked on a reactive client:
● Auto-configuration for ReactiveElasticsearchClient
● Spring Data Reactive Repository
8. ReactiveElasticsearchClient auto-configuration
@Service
public class ReactiveSearchService {
private ReactiveElasticsearchClient client;
public ReactiveSearchService(ReactiveElasticsearchClient client) {
this.client = client;
}
public Flux<SearchHit> search() {
SearchRequest searchRequest = new SearchRequest("tweets");
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.termQuery("hashtags", "pivotalparis"));
searchRequest.source(sourceBuilder);
return this.client.search(searchRequest);
}
}
9. Reactive repository support
public interface TweetRepository
extends ReactiveElasticsearchRepository<Tweet, String> {
Flux<Tweet> findByHashtag(String hashtag);
}
11. Useful Benchmarks are the ones you run
Why running super-artificial benchmarks?
● Testing different parts of the web stack
● Comparing two versions (e.g., a specific patch)
● Measuring Framework overhead
● Optimizing for good latency, stable/predictable behavior,
THEN throughput
● Learning!
Is this a realistic use case?
What are we comparing here?
Show me latencies, percentiles,
error rates!
Is this really your app’s
bottleneck?
Rank your favorite features
(developer productivity, latency,
throughput, preditcability…)
Run your own
14. Spring Boot 2.1.0 vs. 2.2.0-SNAPSHOT
Spring MVC:
● +20-30% req/sec depending on the use case
● Improved latency (75th percentile is now 95th percentile!)
Spring WebFlux:
● +20-40% req/sec, more stable with concurrency
● Annotation model is now on par with Functional one
● Latency -10% overall, lower percentiles are much better
● A lot of it is building up on Reactor Netty’s improvements
This is a very subjective benchmark, you won’t get the same results in your apps!
16. Do we really need another protocol?
For distributed systems, mobile applications:
● Lightweight, efficient (wire format, network)
● Backpressure support at the message level
● High-level, modern communication patterns
● Large ecosystem (transports, programming languages)
● Simple, well defined specification supported by several actors
17. RSocket protocol
Already used at massive scale at Facebook:
● Binary protocol, multiplexed
● Bi-directional (Server/client vs. Requester/Responder)
● Backpressure support at the message level
● Fire and forget, request-response, request-stream, channel
● Session resumption across transports
● TCP, websocket, aeron - Java, JavaScript, C++, Go, .NET, Kotlin
● https://rsocket.io
18. As of Spring Boot 2.2.0:
● spring-boot-starter-rsocket
● @MessageMapping programming model
● “Client” support with RSocketRequester
● JSON and CBOR support out of the box
What’s next: Spring Cloud Gateway support!
RSocket support in Spring