This topic describes how to use Alibaba Cloud Server Load Balancer (SLB) to distribute traffic across multiple StarRocks Frontend (FE) nodes. It also explains how to configure a client-side connection pool to achieve high-concurrency, high-availability, and high-performance database access.
Prerequisites
FE configuration: You need three or more FE nodes.
Network access permissions: The client IP address must be in the security group for internal access or the whitelist for internet access.
Procedure
Step 1: Enable SLB access
By default, EMR Serverless StarRocks uses PrivateZone to access FE nodes. This method does not support load balancing, which can cause an uneven distribution of connections among FE nodes and result in a load imbalance. To resolve this issue, you can enable SLB access to balance the load across FE nodes. You can also configure an optimized client-side connection pool to further improve access efficiency and stability.
Go to the details page of an EMR Serverless StarRocks instance.
Log on to the EMR console.
In the left-side navigation pane, choose .
In the top navigation bar, select a region based on your business requirements.
In the Instances section, find the desired StarRocks instance and click the name of the instance.
In the Gateway Information section, click Activate SLB.
Click OK.
Step 2: Configure a client-side connection pool
Using a connection pool provides the following benefits:
Connection reuse: Reduces the overhead of frequently creating and destroying connections, which lowers system resource consumption.
Lifecycle management: Manages the lifecycle of connections in a unified way to prevent connection leaks.
Concurrency control: Supports a connection queue mechanism to gracefully handle a high volume of concurrent requests during peak hours.
Validity checks: Automatically detects invalid connections to ensure that each query uses a valid connection.
Monitoring and tuning: Provides detailed monitoring metrics, such as the number of FE connections, for real-time monitoring of the connection pool status.
SDK method (Java and HikariCP example)
Maven dependencies
Add the following dependencies to the
pom.xmlfile of your project.<dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>5.0.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.33</version> </dependency>HikariCP connection pool configuration
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; public class StarRocksConnectionPoolExample { public static void main(String[] args) { // Configure the HikariCP connection pool HikariConfig config = new HikariConfig(); // Internal same-region endpoint config.setJdbcUrl("jdbc:mysql://fe-c-xxx-internal.starrocks.aliyuncs.com:9030/<yourDatabase>"); config.setUsername("<yourUsername>"); config.setPassword("<yourPassword>"); // Configure core parameters config.setMaximumPoolSize(20); // Set the maximum number of connections to 20. config.setMinimumIdle(5); // Set the minimum number of idle connections to 5. config.setConnectionTimeout(30000); // Set the connection timeout to 30 seconds (30,000 milliseconds). config.setIdleTimeout(600000); // Set the idle connection timeout to 10 minutes (600,000 milliseconds). config.setMaxLifetime(1800000); // Set the maximum lifetime of a connection to 30 minutes (1,800,000 milliseconds). config.setConnectionTestQuery("SELECT 1"); // Health check SQL query config.setValidationTimeout(5000); // Validation timeout config.setLeakDetectionThreshold(60000); // Connection leak detection (1 minute) // Create the data source HikariDataSource dataSource = new HikariDataSource(config); // Use the connection pool to execute a query try (Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT count(*) FROM your_table"); ResultSet rs = stmt.executeQuery()) { if (rs.next()) { System.out.println("Count: " + rs.getLong(1)); } } catch (Exception e) { e.printStackTrace(); } } }
BI tool configuration
Common BI tools, such as Tableau, Superset, Metabase, and Quick BI, support setting connection pool parameters in their advanced options.
Step 3: Verify the load balancing effect
Go to the Monitoring And Alerting page of the target StarRocks instance and click the Instance tab. Then, view the FE Connections monitoring graph in the FE Net section.
Confirm that the connections are evenly distributed among the FE nodes. If the distribution is uneven, adjust the client-side connection pool parameters or check the SLB configuration.
Step 4: Tune load balancing
You can dynamically adjust the following parameters to optimize performance as needed.
Parameter | Recommended value | Description |
| 10 to 50 | Sets the maximum number of connections allowed in the pool. This controls the upper limit for concurrent connections. Adjust this value based on your application's concurrency. A recommended initial value is 20. A value that is too high can waste resources. |
| 5 to 10 | Sets the minimum number of idle connections maintained in the pool. This avoids frequently creating new connections during a cold start. |
| 30 s | Sets the maximum time to wait for a connection from the pool. An exception is thrown if this time is exceeded. |
| 600 s (10 minutes) | Sets the time that an idle connection can remain in the pool. After this time, the connection is revoked. |
| 1800 s (30 minutes) | Sets the maximum lifetime of a single connection. After this time, the connection is forcibly closed and a new one is created. |
|
| Sets the SQL query used to detect the validity of a connection. This ensures that connections in the pool are always active. StarRocks supports this statement to verify that the connection is working correctly. |
Using Alibaba Cloud SLB and a client-side connection pool, you can effectively resolve load balancing issues for multiple StarRocks FE nodes while improving system stability and performance. Configure the connection pool parameters based on your business needs and regularly monitor the system status to ensure optimal performance.