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

Schematic 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 service thread pools. Service thread pools are a subcategory of default business thread pools.

Configure a default thread pool

A provider thread pool is used to run business logic. By default, its core size is 50, maximum size is 720, and keepAliveTime is 500s. SynchronousQueue is used by queuing. User requests are not accumulated because queues are not cached. New requests are immediately denied with the error message "Thread pool is full" when all threads (720 in total) of a provider thread pool are processing requests. You can configure the pool by setting 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 service thread pool

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

  • Configure the service thread pool for HSF services through API programming
    HSFApiProviderBean hsfApiProviderBean = new HSFApiProviderBean();
    //...
    hsfApiProviderBean.setCorePoolSize("50");
    hsfApiProviderBean.setMaxPoolSize("200");
  • Configure the service thread pool for HSF services through Spring configuration

    Spring is a framework widely used by applications. You can configure HSF services through Spring XML. The following XML configuration has the same effect as the preceding API programming:

    <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 the service thread pool for HSF services through annotations

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

    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 type.
      The following annotation configuration has the same effect as the preceding API programming:
      @ 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);
          }
      }