This topic describes how to configure a provider thread pool when you develop High-Speed Service Framework (HSF) applications.

Prerequisites

Diagram of a provider thread pool

An HSF provider thread pool includes I/O threads and business threads. The I/O thread model is used in Reactor Netty. This topic describes how to configure a business thread pool. Business thread pools are classified into default business thread pools and provider thread pools. Provider thread pools are a subcategory of default thread pools.

Configure a default thread pool

A provider thread pool is used to run business logic. By default, the core size of the thread pool is 50, the maximum size is 720, and the value of keepAliveTime is 500s. SynchronousQueue is used. User requests are not accumulated because queues are not cached. When all the threads (720 in total) of a provider thread pool are processing requests, new requests are immediately denied and the error message "Thread pool is full" is returned. You can configure the pool by specifying the following VM parameters (-D parameters):

  • Minimum pool size: -Dhsf.server.min.poolsize
  • Maximum pool size: -Dhsf.server.max.poolsize
  • Keepalive time of thread convergence: -Dhsf.server.thread.keepalive

Configure a provider thread pool

You can configure thread pools that exclusively process slow services and high concurrency. This prevents excessive usage of business threads and protects service calls made by applications.

  • Configure HSF services by using API
    HSFApiProviderBean hsfApiProviderBean = new HSFApiProviderBean();
    //...
    hsfApiProviderBean.setCorePoolSize("50");
    hsfApiProviderBean.setMaxPoolSize("200");
  • Configure HSF services by using the Spring Framework

    The Spring Framework is a component that is widely used in applications. If you do not want to configure HSF services by using API, you can configure them by using Spring XML. The following XML configuration has the same effect as the API configuration in the preceding example:

    <bean class="com.taobao.hsf.app.spring.util.HSFSpringProviderBean" init-method="init">
        <! --Set the interface for service publishing. -->
        <property name="serviceInterface" value="com.alibaba.middleware.hsf.guide.api.service.OrderService"/>
        <property name="corePoolSize" value="50" />
        <property name="maxPoolSize" value="200" />
    </bean>
  • Configure HSF services by using annotations

    Spring Boot is widely used. You can use annotations to configure Spring beans. You can also use annotations to configure HSF services for publishing.

    1. Add the starter dependency to the project.
      <dependency>
          <groupId>com.alibaba.boot</groupId>
          <artifactId>pandora-hsf-spring-boot-starter</artifactId>
      </dependency>
    2. Configure @HSFProvider to the implementation class.
      The following annotation configuration has the same effect as the API configuration in the preceding example:
      @HSFProvider(serviceInterface = OrderService.class, corePoolSize = 50, maxPoolSize = 200)
      public class OrderServiceImpl implements OrderService {
          @Autowired
          private OrderDAO orderDAO;
      
          @Override
          public OrderModel queryOrder(Long id) {
              return orderDAO.queryOrder(id);
          }
      }