Know your Byte Code

This is an amazing write-up: https://github.com/brettwooldridge/HikariCP/wiki/Down-the-Rabbit-Hole

HikariCP offers a high-performance JDBC Pool

Manage Node Connection Provider

Curator Framework simplifies ZooKeeper :  offers robust management for distributed systems.

Ref : http://curator.apache.org/curator-framework/

Automatic connection management:

  • There are potential error cases that require ZooKeeper clients to recreate a connection and/or retry operations. Curator automatically and transparently (mostly) handles these cases.
  • Watches for NodeDataChanged events and calls updateServerList() as needed.
  • Watches are automatically removed by Curator recipes

Cleaner API:

  • simplifies the raw ZooKeeper methods, events, etc.
  • provides a modern, fluent interface

Recipe implementations (see Recipes):

  • Leader election
  • Shared lock
  • Path cache and watcher
  • Distributed Queue
  • Distributed Priority Queue

More specifically ,

The Curator Framework constantly monitors the connection to the ZooKeeper ensemble. Further every operation is wrapped in a retry mechanism. Thus, the following guarantees can be made:

  • Every Curator operation properly waits until the ZooKeeper connection is established
  • Every Curator Framework operation (create, getData, etc.) is guaranteed to manage connection loss and/or session expiration per the currently set retry policy
  • If the connection is temporarily lost, Curator will attempt to retry the operation until it succeeds per the currently set retry policy
  • All Curator recipes attempt to deal with connection issues in an appropriate way

Always Manage Executor Threads:

  • com.google.common.util.concurrent.MoreExecutors — converts the given ThreadPoolExecutor into an ExecutorService that exits when the application is complete.
  • Example :
    • maintain a safe map of listeners –  private final Map<T, ListenerEntry<T>> listeners = Maps.newConcurrentMap();
    • each listenerEntry caontains – addListener(listener, MoreExecutors.sameThreadExecutor());

Provide a Facade over Queue:

Since a queue can handle only certain number of items, say ZooKeeper’s transport layer ,  a facade like QueueSharder can be used to monitor the queues and if any one of them goes over a threshold, a new queue is added.

Always broadcast Notifications :

ConnectionStateListenable().addListener(new ConnectionStateListener() {
public void stateChanged(CuratorFramework client, ConnectionState newState) {
                System.out.println(“** STATE CHANGED TO : ” + newState);
            }
        });

Provide pluggable Error Policies

Track the Metrics

ex. Servo provides a simple interface for exposing and publishing application metrics , MetricsConsumerBolt

Enqueue streaming data and process streams

example: create an Storm Event Processing topology :

  • generate Spout configs (scheme, offsetTime, buffSize, fetchMaxWait, socketTimeout….)
  • spawn QueueSpout (say Kafka)
  • tighten the input and output Bolts
    • leverage the fact that this Bolt can accept a Tuple and emit collection to OutputCollector.
  • config Storm Nimbus
  • submit Topology to a cluster

Embrace smart messaging proxy

Example :  Fabric8MQ

  1. Protocol Conversion — by moving MQTT,STOMP,AMQP protocol conversion outside of the ActiveMQ broker reduces the amount of work the broker needs to do: As ActiveMQ isn’t well designed for modern, asynchronous tasks, the less work the broker does, the better.
  2. Camel Routing is built right into the router — so we can easily convert on the fly between, say Topics (Publish/Subscribe) and Queues (point-2-point).
  3. API Management — utlizing API Man, so you can apply security and rate limiting policies to destinations
  4. Multiplexer — reducing the amount of physical connections an ActiveMQ broker has, increases the throughput of the overall system.
  5. Destination Sharding — this is where a lot of the magic pixie dust is used, to shard connections across many different backend ActiveMQ brokers. Its also where messages and clients are moved between brokers, as brokers are spun up and down, depending on load
  6. Broker Control — this monitors the brokers under Fabric8MQ’s control and monitors load — and it decides if more ActiveMQ brokers are needed, or less — depending on load. An embedded rules engine is used to make the decisions.

Always adopt a flexible Test framework:

http://joel-costigliola.github.io/assertj/

http://www.scalatest.org/

Adopt a highly efficient and expressive Data Structure:

example : https://code.google.com/p/guava-libraries/wiki/GuavaExplained

 excerpts from .. http://engineering.datarank.com/2015/04/28/choosing-a-collection-library-in-java.html
 6 public Iterable<Integer> findAllIdsForLastNameSortedByIdUsingJava7(
 7         Iterable<Person> people, String lastName) {
 8
 9     return FluentIterable
10             .from(people)
11             .filter(new Predicate<Person>() {
12                 public boolean apply(Person input) {
13                     return input.getLastName().equals(lastName);
14                 }
15             })
16             .transform(new Function<Person, Integer>() {
17                 public Integer apply(Person input) {
18                     return input.getId();
19                 }
20             })
21             .toSortedList(Ordering.natural());
22 }

References : http://www.goldmansachs.com/gs-collections/documents/GS%20Collections%20Training%20Session%20and%20Kata%205.0.0.pdf

  • MutableList<Address> addresses = people.collect(Person.TO_ADDRESS);
public class Person {
public static final Function<Person, Address> TO_ADDRESS = person -> person.getAddress();
}
  • MutableList<Person> adults = people.select(each -> each.getAge() >= 18);

many more cool high-performance library ..  Agrona  , FastUtil

Simplify Regex Handling:

Finally a Great Library :  https://github.com/VerbalExpressions/JavaVerbalExpressions

VerbalExpression testRegex = VerbalExpression.regex() .startOfLine().then(http).maybe(s) .then(://) .maybe(www.).anythingBut( ) .endOfLine() .build();

 

Always use an efficient Serializer:

eg: Kryo is a fast and efficient object graph serialization framework …

Track latency of Operations:

https://github.com/LatencyUtils/LatencyUtils

Servers should use Non-Blocking-IO

e.g.  Netty , Grizzly

For fast reactive task execution use CompleteableFuture

aa

Result Processors via CompletebaleFuture chain – https://youtu.be/Q_0_1mKTlnY?t=1251 ,

Combining multiple completable futures ~ https://www.infoq.com/articles/Functional-Style-Callbacks-Using-CompletableFuture

Ref: https://www.youtube.com/watch?v=Q_0_1mKTlnY


Excellent InfoQ Presentation ~ https://www.infoq.com/presentations/java8-lambdas-streams


Leverage ‘string joining’, ‘static interface methods’.’sorting’,’grouping’,’combining predicates’,’parallel streams’ ~ https://www.youtube.com/watch?v=GphO9fWhlAg , https://www.youtube.com/watch?v=873E68cylNo

Refactoring to Functional Style with Java 8 , Reactive programming patterns in Java

https://www.infoq.com/presentations/reactor-core-flux-mono


A Crash Course in Modern Hardware by Cliff Click

http://www.javaperformancetuning.com/news/newtips192.shtml


Finally the Java libraries you can never miss !

Production~ Guice, Guava,OkHttp, Retrofit, JDeferred, RxJava,Mbassador,Lombok (pojo Generator) ,Slf4j

Test~ Jukito, Awaitility, Spock,WireMock,Mockito,JunitParams

Guava UtilsJava 8 Collections , Java Object Size


Enterprise Java Apps ~ using Cassandra and Spring Connector – http://docs.spring.io/spring-data/cassandra/docs/2.0.0.M1/reference/html/

Comprehensive testing using Spring MockMvc ~ https://www.infoq.com/presentations/spring5-mvc-test


Spring 5 now support reactor-streams ~ a key feature to build low-latency application (handling  back pressure and supporting declarative-style composition API)

reactor_streams


Nice Explanation of Bloom Filter ~ http://cs.unc.edu/~fabian/courses/CS600.624/slides/bloomslides.pdf

Performance Tuning ~ https://dzone.com/articles/java-memory-and-cpu-monitoring-tools-and-technique

Advertisements