Application-level configuration

更新时间:
复制 MD 格式

This topic describes the available configuration items and common configurations for SOFARPC.

Basic configuration items

Add the following configuration items to the application.properties file as needed for your environment:

Configuration item

Type

Description

Default value

sofa_runtime_local_mode

BOOLEAN

Enables or disables local-first invocation.

false

run_mode

STRING

The RPC running mode. Set this based on your actual environment.

empty

rpc_tr_port

INTEGER

The TR port number.

12200

rpc_bind_network_interface

STRING

Binds the server to a specific network interface controller (NIC).

empty

rpc_enabled_ip_range

STRING

Binds the server to a local IP address range.

empty

rpc_min_pool_size_tr

INTEGER

The minimum number of threads in the TR server thread pool.

20

rpc_max_pool_size_tr

INTEGER

The maximum number of threads in the TR server thread pool.

200

rpc_pool_queue_size_tr

INTEGER

The queue size of the TR server thread pool.

0

com.alipay.sofa.rpc.bolt.port

INTEGER

The Bolt port number.

12200

com.alipay.sofa.rpc.bolt.thread.pool.core.size

INTEGER

The minimum number of threads in the Bolt server thread pool.

20

com.alipay.sofa.rpc.bolt.thread.pool.max.size

INTEGER

The maximum number of threads in the Bolt server thread pool.

200

com.alipay.sofa.rpc.bolt.thread.pool.queue.size

INTEGER

The queue size of the Bolt server thread pool.

0

com.alipay.sofa.rpc.rest.port

INTEGER

The SOFAREST port number.

8341

rpc_transmit_url

STRING

Configuration for prefetch and weight.

empty

rpc_transmit_url_timeout_tr

INTEGER

The timeout period for prefetch calls, in ms.

0

rpc_profile_threshold_tr

INTEGER

The threshold for printing RPC service processing performance logs, in ms.

300

Local-first invocation pattern

To prioritize local service invocations between multiple SOFA applications and bypass software load balancing, add sofa_runtime_local_mode=true to the application.properties file.

However, the sofa_runtime_local_mode configuration still depends on the addresses pushed from the configuration center. After obtaining the list of service provider addresses, the service consumer prioritizes the local IP address for service invocation. If a developer's workspace does not have a configuration center, you must specify the service provider's address for the invocation. For more information, see Routing and configuration center.

application.properties: 

run_mode=TEST

<!--Service consumer configuration-->
<sofa:reference ...>
     <sofa:binding.bolt>
         <global-attrs test-url="localhost:12200"/>
     </sofa:binding.bolt>
</sofa:reference>

IP address or NIC binding

By default, when SOFARPC publishes a service endpoint, it selects the IP address of the first local NIC to publish to the configuration center. If multiple NICs are present, such as on the SOFAStack platform where both private and public IP addresses exist, you must set an IP selection policy.

SOFARPC provides two ways to select an IP address:

  • rpc_bind_network_interface

    Specify the NIC name to use, for example: rpc_bind_network_interface=eth0.

  • rpc_enabled_ip_range

    Specify an IP address range to bind. The format is IP_RANGE1:IP_RANGE2,IP_RANGE. For example, rpc_enabled_ip_range=192.168.1:192.168.2,10 means that only IP addresses in the ranges 192.168.1.0 to 192.168.2.255 and 10.0.0.0 to 10.255.255.255 are selected.

    Note

    On the SOFAStack platform, all private network addresses are bound to the eth0 NIC. You can use the rpc_bind_network_interface=eth0 configuration directly. If the application runs on a platform other than SOFAStack, check the machine's private network address and modify the configuration accordingly. You can use the following commands to view the machine's address:

    • Windows: ipconfig

    • macOS and Linux: ifconfig

TR thread pool configuration

You can use the following options in the application.properties file to configure the TR thread pool:

  • com.alipay.sofa.rpc.bolt.thread.pool.core.size: The number of core threads. The default is 20.

  • com.alipay.sofa.rpc.bolt.thread.pool.max.size: The maximum number of threads. The default is 200.

  • com.alipay.sofa.rpc.bolt.thread.pool.queue.size: The size of the thread queue. The default is 0.

TR uses the ThreadPoolExecutor from the Java Development Kit (JDK). When new requests arrive, the pool creates threads up to the core thread count. After the core thread count is reached, new requests are placed in the thread queue. If the queue becomes full, the pool creates additional threads up to the maximum thread count. If the maximum thread count is reached and the queue is full, subsequent requests are rejected with a RejectionException.