Click here to close now.




















Welcome!

Microservices Expo Authors: Carmen Gonzalez, Elizabeth White, Liz McMillan, Jason Bloomberg, Pat Romanski

Blog Feed Post

Getting the maximum performance of your Java processes

therore-concurrent provides self-tuning thread-pools helping you to make the most of your system.

Recently, I have been working in the optimization of an OLTP system. The software has a SEDA architecture (Staged Event Driven Architecture) with lots of threads doing little works. I had to fight with the hard task of adjusting a hundred of parameters. Each of those parameters affected some others and so on.

For example if the number of concurrent database connections is set too low, it would cause a contention in getting connections. On the contrary, if that number is set too high, it could cause a lock-contention in the database when the threads want to access to some shared resources (index, row, block, etc.)

Even more, not always the processing of an event requires the same type of resources. A sudden change in the type of events that are being treated, can turn an optimal configuration into a suboptimal.

One of the most significant parameters is the number of threads assigned for each component. It is difficult to choose a good value if you don’t know how much the threads use each type of resource and how much are they coupled between each other.

Usually certain tasks have a higher priority and should be processed as soon as possible. This further complicates the choice of the configuration. Enforcing priorities and maximizing throughputs are opposite goals therefore it is necessary to define the scope of both.

In my experience a huge configurability can work against you. In a medium/big SOA system with a lot of service communications and complex workload profiles that even change over time, is almost impossible to get the optimal value for each of those parameters. Because of that I found interesting to develop a library that might be able to adapt quickly at runtime in order to make the most of the system.

Self-tuning thread-pool

Nowadays creating threads manually is not very common. Instead of that, thread-pools are frequently used. A thread-pool manages the creation and allocation of threads. JDK comes with some interesting and useful classes for managing threads. I list two of the most important:

  • ThreadPoolExecutor is a very flexible and configurable thread-pool that supports customization of queue size, minimum and maximum pool size, keep-alive time, etc.
  • Executors is a convenient class that creates thread-pools for the most usual cases.

I have developed the library therore-concurrent that takes advantage of those classes and extends some functionalities. The library contains analogous to the above classes.

  • SelfTuningExecutorService is a thread-pool that implements a mechanism for searching a good value for the pool size. The algorithm tries to maximize the throughput respecting the thread-pool priorities.
  • SelfTuningExecutors acts as the factory of SelfTuningExecutorService. It is recommended to use it as a singleton.

The following charts show how quickly SelfTuningExecutorService finds the optimal value.

selftuning_poolsize_executions_chart

Using SelfTuningExecutors directly

  • Add the dependency to the pom
  • <dependency>
        <groupId>net.therore</groupId>
        <artifactId>therore-concurrent</artifactId>
        <version>1.1.0</version>
    </dependency>
    

  • The following snippet shows how can it be used.
  • SelfTuningExecutors executors = SelfTuningExecutors.defaultSelfTuningExecutors();
    ExecutorServicce service = executors.newSelfTuningExecutor("executor-for-test", corePoolSize, initPoolSize
           , maximumPoolSize, priority, queueSize);
    service.execute(task);
    

The only new parameters are initPoolSize and priority.

  • initPoolSize is the initial amount of threads assigned to the pool.
  • priority is a positive number that works for SelfTuningExecutorService to limit the number of threads of this pool regarding others.

Integrating SelfTuningExecutors with Quartz Scheduler

Quartz-Scheduler has his own thread-pool interface and its name is “ThreadPool” (not surprise). The class SelfTuningThreadPool that is in the artifact therore-concurrent-quartz implements such interface. Integrating it is very easy, follow these steps:

  • Add the dependency to the pom
  • <dependency>
        <groupId>net.therore</groupId>
        <artifactId>therore-concurrent-quartz</artifactId>
        <version>1.1.0</version>
    </dependency>
    

  • Change the configuration properties of quartz
  • # org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
    # org.quartz.threadPool.threadCount = 1
    # org.quartz.threadPool.threadPriority = 5
    org.quartz.threadPool.class = net.therore.concurrent.quartz.SelfTuningThreadPool
    org.quartz.threadPool.corePoolSize = 1
    org.quartz.threadPool.initPoolSize = 1
    org.quartz.threadPool.maximumPoolSize = 100
    org.quartz.threadPool.priority = 5
    org.quartz.threadPool.queueSize = 2
    

Integrating SelfTuningExecutors with Apache Camel

I love Apache Camel. It offers a lot of components supporting integration with different technologies. But if none of them actually help you yet, it’s pretty easy to make your own component.

Camel’s team has thought very well the threading model. They use the concept (and interface) of ThreadPoolProfile which is a kind of thread-pool-template that you can use to instantiate several pools with the same configuration. If that is not enough, you can program your own implementation of ExecutorServiceManager, the Camel’s thread-pool provider. Simplifying, think about it like the Executors class of the JDK.

I’ve just done that, SelfTunigExecutorServiceManager is the name of my own implementation of ExecutorServiceManager. It is located in other maven module therore-concurrent-camel. I’ll explain how to use it.

  • Add the dependency to the pom
  • <dependency>
        <groupId>net.therore</groupId>
        <artifactId>therore-concurrent-camel</artifactId>
        <version>1.1.0</version>
    </dependency>
    

  • The following snippet contains two connected routes with SEDA component and SelfTunigExecutorServiceManager
  • SelfTunigExecutorServiceManager executorManager = new SelfTunigExecutorServiceManager(context);
    context.setExecutorServiceManager(executorManager);
    ThreadPoolProfile profile = new ThreadPoolProfile();
    profile.setId("self-tuning-profile");
    profile.setMaxPoolSize(100);
    profile.setMaxQueueSize(100);
    profile.setDefaultProfile(true);
    executorManager.setDefaultThreadPoolProfile(profile);        
    
    final String sedaEndpointUri = "seda:myseda?blockWhenFull=true&size=1";
    context.addRoutes(new RouteBuilder() {
       @Override
       public void configure() throws Exception {
           from("direct:in")
           .to(sedaEndpointUri);
       }
    });
    context.addRoutes(new RouteBuilder() {
       @Override
       public void configure() throws Exception {
           from(sedaEndpointUri)
           .threads(1, 100)
           .to("bean:mybean");
       }
    });
    
    ProducerTemplate template = context.createProducerTemplate();
    context.start();
    for (int i=0; i<ITERATIONS; i++) {
       template.sendBody("direct:in", "dummy string");
    }
    

Summary

I have figured out that there are many elements that might turn into selftuning ones. I chose ThreadPool because from my point of view is one of the most important, used and easy to test element.

Moreover, most of the modern libraries and frameworks feature different ways to extend their factories, providers and templates. All of that aims to develop general purpose classes and integrate them with lots of frameworks.

Read the original blog entry...

More Stories By Alfredo Diaz

Alfredo Diaz is a Java EE Architect with over 10 years of experience. He is an expert in SOA, real-time processing, scalability and HA. He is an Agile enthusiast.

@MicroservicesExpo Stories
DevOps Summit, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait for long development...
Whether you like it or not, DevOps is on track for a remarkable alliance with security. The SEC didn’t approve the merger. And your boss hasn’t heard anything about it. Yet, this unruly triumvirate will soon dominate and deliver DevSecOps faster, cheaper, better, and on an unprecedented scale. In his session at DevOps Summit, Frank Bunger, VP of Customer Success at ScriptRock, will discuss how this cathartic moment will propel the DevOps movement from such stuff as dreams are made on to a prac...
SYS-CON Events announced today that DataClear Inc. will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. The DataClear ‘BlackBox’ is the only solution that moves your PC, browsing and data out of the United States and away from prying (and spying) eyes. Its solution automatically builds you a clean, on-demand, virus free, new virtual cloud based PC outside of the United States, and wipes it clean...
The word quantum often portends New Age mumbo-jumbo, in spite of the fact that quantum mechanics underlies many of today’s most important technologies, including lasers and the semiconductors found in every computer chip. Nevertheless, today quantum computing is becoming a reality. And while it may look to the layperson like mere mumbo-jumbo, in reality of the technology has largely moved out of the theoretical stage, as recent news indicates. In fact, two important announcements over the la...
Any Ops team trying to support a company in today’s cloud-connected world knows that a new way of thinking is required – one just as dramatic than the shift from Ops to DevOps. The diversity of modern operations requires teams to focus their impact on breadth vs. depth. In his session at DevOps Summit, Adam Serediuk, Director of Operations at xMatters, Inc., will discuss the strategic requirements of evolving from Ops to DevOps, and why modern Operations has begun leveraging the “NoOps” approa...
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades. With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo, November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Learn what is going on, contribute to the discussions, and e...
In today's digital world, change is the one constant. Disruptive innovations like cloud, mobility, social media, and the Internet of Things have reshaped the market and set new standards in customer expectations. To remain competitive, businesses must tap the potential of emerging technologies and markets through the rapid release of new products and services. However, the rigid and siloed structures of traditional IT platforms and processes are slowing them down – resulting in lengthy delivery ...
Early in my DevOps Journey, I was introduced to a book of great significance circulating within the Web Operations industry titled The Phoenix Project. (You can read our review of Gene’s book, if interested.) Written as a novel and loosely based on many of the same principles explored in The Goal, this book has been read and referenced by many who have adopted DevOps into their continuous improvement and software delivery processes around the world. As I began planning my travel schedule last...
In his session at 17th Cloud Expo, Ernest Mueller, Product Manager at Idera, will explain the best practices and lessons learned for tracking and optimizing costs while delivering a cloud-hosted service. He will describe a DevOps approach where the applications and systems work together to track usage, model costs in a granular fashion, and make smart decisions at runtime to minimize costs. The trickier parts covered include triggering off the right metrics; balancing resilience and redundancy ...
17th Cloud Expo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Meanwhile, 94% of enterprises ar...
SYS-CON Events announced today the Containers & Microservices Bootcamp, being held November 3-4, 2015, in conjunction with 17th Cloud Expo, @ThingsExpo, and @DevOpsSummit at the Santa Clara Convention Center in Santa Clara, CA. This is your chance to get started with the latest technology in the industry. Combined with real-world scenarios and use cases, the Containers and Microservices Bootcamp, led by Janakiram MSV, a Microsoft Regional Director, will include presentations as well as hands-on...
SYS-CON Events announced today that the "Second Containers & Microservices Expo" will take place November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Containers and microservices have become topics of intense interest throughout the cloud developer and enterprise IT communities.
Akana has announced the availability of the new Akana Healthcare Solution. The API-driven solution helps healthcare organizations accelerate their transition to being secure, digitally interoperable businesses. It leverages the Health Level Seven International Fast Healthcare Interoperability Resources (HL7 FHIR) standard to enable broader business use of medical data. Akana developed the Healthcare Solution in response to healthcare businesses that want to increase electronic, multi-device acce...
The web app is agile. The REST API is agile. The testing and planning are agile. But alas, data infrastructures certainly are not. Once an application matures, changing the shape or indexing scheme of data often forces at best a top down planning exercise and at worst includes schema changes that force downtime. The time has come for a new approach that fundamentally advances the agility of distributed data infrastructures. Come learn about a new solution to the problems faced by software organ...
Containers are not new, but renewed commitments to performance, flexibility, and agility have propelled them to the top of the agenda today. By working without the need for virtualization and its overhead, containers are seen as the perfect way to deploy apps and services across multiple clouds. Containers can handle anything from file types to operating systems and services, including microservices. What are microservices? Unlike what the name implies, microservices are not necessarily small,...
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading in...
Docker containerization is increasingly being used in production environments. How can these environments best be monitored? Monitoring Docker containers as if they are lightweight virtual machines (i.e., monitoring the host from within the container), with all the common metrics that can be captured from an operating system, is an insufficient approach. Docker containers can’t be treated as lightweight virtual machines; they must be treated as what they are: isolated processes running on hosts....
Puppet Labs is pleased to share the findings from our 2015 State of DevOps Survey. We have deepened our understanding of how DevOps enables IT performance and organizational performance, based on responses from more than 20,000 technical professionals we’ve surveyed over the past four years. The 2015 State of DevOps Report reveals high-performing IT organizations deploy 30x more frequently with 200x shorter lead times. They have 60x fewer failures and recover 168x faster
Microservice architecture is fast becoming a go-to solution for enterprise applications, but it's not always easy to make the transition from an established, monolithic infrastructure. Lightweight and loosely coupled, building a set of microservices is arguably more difficult than building a monolithic application. However, once established, microservices offer a series of advantages over traditional architectures as deployment times become shorter and iterating becomes easier.