Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips October 2018
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 215 contents
https://www.youtube.com/watch?v=_stAxdjx8qk
How (Not) to use Reactive Streams in Java 9+ (Page last updated July 2018, Added 2018-10-29, Author Jacek Kunicki, Publisher Devoxx). Tips:
- Strategies to deal with a slow consumer: drop data (routers do this); block (slows processing); buffer (but this is limited, only handles bursty traffic otherwise need to do one of the other strategies too); backpressure (tell the producer to send more slowly); aggregate in the producer; drop connection.
- A Flow implementation needs to pass the TCK test suite to be correct - make sure to run against the TCK if you implement Flow components.
- Flow is fundamentally asynchronous, and a simple implementation can be full of subtle concurrency bugs. Use the provided SPIs or libraries like project reactor, akka streams or rxjava (which all can convert to the flow interfaces so can actually work with each other without even knowing each other's implementations).
- Flow is potentially a stream unification layer for the multiple streaming abstractions in core Java: java.io byte streams, java.util.Iterator element streams, java.nio channels, javax.servlet Listeners, jdbc result sets, Java8 Streams, and Flow; but it lacks operation abstractions.
https://www.youtube.com/watch?v=T8kiNPrgf4M
Performance Analysis in the Cloud (Page last updated August 2018, Added 2018-10-29, Author Mohit Chawla, Publisher FrOSCon). Tips:
- Queueing theory provides a good basis for modeling performance of many applications.
- For a simple queue of one server and random arrival rates, the utilization is arrival rate x service time, the time spent in the queue is service time divided by 1-utilization, and the average queue length is arrival rate x the time spent in the queue.
- A package like PDQ is useful to model a system of queues which is the totality of an application for end-to-end request processing.
- For a heterogenous server resource environment, eg when targeting server costs and using the cheapest available resources to serve the full scale required (eg AWS spot), a simple queueing model is of no use, and you need to accurately model your system to ensure you can adequately predict scaling.
- You can model the performance of your application at design time, which gives you a huge step up in predicting your system's performance and adapting the design to achieve what you need.
https://www.infoq.com/presentations/dl-performance-optimization
Deep Learning for Application Performance Optimization (Page last updated August 2018, Added 2018-10-29, Author Zoran Sevarac, Publisher QCon). Tips:
- Performance tuning is specific to the application, the load on it, and the infrastructure it runs on. It's typically time consuming and requires repeated tests for even small changes.
- Performance tuning is actually a typical (regression) machine learning problem - an unknown function with data that can be learned to give a prediction for specific cases.
- For applying machine learning to performance optimization, typical inputs would be: number of concurrent users, request rate, core count, memory available, and other applicable config settings appropriate to your application that affect performance. Typical outputs would be response times, apdex score, total execution time (for batches), garbage collection (pause, etc). The procedure to follow is: collect data from load tests, process clean & prepare the data, build the model, evaluate the model using the test data, test the model in production, repeat as needed.
https://www.youtube.com/watch?v=Zm3OgyQfDTU
Concurrency for humans (Page last updated July 2018, Added 2018-10-29, Author Cay Horstmann, Publisher Jug.ru). Tips:
- Explicitly locking on an object that is publicly available is a maintenance anti-pattern - use private locks.
- Callable's are like Runnables but can throw exceptions and return results. You can parallelize a combinable computation by creating a group of Callables and then process the Futures that result.
- Pick the right executor: a fixed size thread pool (sized to the available cores) is appropriate for computationally expensive tasks; a variable sized pool is appropriate for tasks that are short or block a lot; a ForkJoinPool is appropriate for computationally expensive tasks that can be decomposed into subtasks.
- A blocked thread uses resources but does no work. Async with callbacks avoids blocking. CompleteableFutures is the current optimal way to execute asynchronously. Use the async methods and supply an executor that is appropriate for the task set.
- If you want to run more than 2 tasks in parallel and combine results, CompleteableFuture is not ideal, you need to run allOf() but combine in the task rather than the returned values.
- Canceling a CompleteableFuture does not interrupt the underlying thread, so it won't terminate the task.
- Parallel streams are ideal for substantial in-memory work. Gathering data from outside memory for processing would overwhelm any benefit; similarly if the work is small, going parallel will actually make it take more time than staying sequential. Any data structure used needs to be splittable (processed in parallel), and any lambdas used in the stream need to be threadsafe (avoid updating shared variables).
- Blocking lambdas in a stream can starve the underlying fork-join pool.
- The best strategy to manage concurrency is confinement - don't share data amongst tasks, combine results in a separate task. The next best is to use immutability.
Jack Shirazi
Back to newsletter 215 contents
Last Updated: 2024-12-27
Copyright © 2000-2024 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips215.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us