Skip to content

Commit

Permalink
Merge pull request #1987 from dilanSachi/5.x-expose-timeout-config
Browse files Browse the repository at this point in the history
[5.x] Expose http connection eviction configurations in the client level
  • Loading branch information
dilanSachi authored May 7, 2024
2 parents df391af + 22f1be8 commit 12ea5e3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ballerina/http_client_connection_pool.bal
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ configurable int maxActiveStreamsPerConnection = 100;
# + maxIdleConnections - Maximum number of idle connections allowed per pool.
# + waitTime - Maximum amount of time (in seconds), the client should wait for an idle connection before it sends an error when the pool is exhausted
# + maxActiveStreamsPerConnection - Maximum active streams per connection. This only applies to HTTP/2. Default value is 100
# + minEvictableIdleTime - Minimum evictable time for an idle connection in seconds. Default value is 5 minutes
# + timeBetweenEvictionRuns - Time between eviction runs in seconds. Default value is 30 seconds
public type PoolConfiguration record {|
int maxActiveConnections = maxActiveConnections;
int maxIdleConnections = maxIdleConnections;
decimal waitTime = waitTime;
int maxActiveStreamsPerConnection = maxActiveStreamsPerConnection;
decimal minEvictableIdleTime = 300;
decimal timeBetweenEvictionRuns = 30;
|};
//This is a hack to get the global map initialized, without involving locking.
class ConnectionManager {
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This file contains all the notable changes done to the Ballerina HTTP package th
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
- [Expose HTTP connection eviction configurations in the client level](https://github.com/ballerina-platform/ballerina-library/issues/6503)

## [2.7.5] - 2024-03-13

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ public class HttpConstants {
public static final BString CONNECTION_POOLING_WAIT_TIME = StringUtils.fromString("waitTime");
public static final BString CONNECTION_POOLING_MAX_ACTIVE_STREAMS_PER_CONNECTION = StringUtils.fromString(
"maxActiveStreamsPerConnection");
public static final BString CONNECTION_POOLING_EVICTABLE_IDLE_TIME = StringUtils.fromString(
"minEvictableIdleTime");
public static final BString CONNECTION_POOLING_TIME_BETWEEN_EVICTION_RUNS = StringUtils.fromString(
"timeBetweenEvictionRuns");
public static final String HTTP_CLIENT_CONNECTION_POOL = "PoolConfiguration";
public static final String CONNECTION_MANAGER = "ConnectionManager";
public static final int POOL_CONFIG_INDEX = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,14 @@ public static void populatePoolingConfig(BMap poolRecord, PoolConfiguration pool
maxActiveStreamsPerConnection == -1 ? Integer.MAX_VALUE : validateConfig(
maxActiveStreamsPerConnection,
HttpConstants.CONNECTION_POOLING_MAX_ACTIVE_STREAMS_PER_CONNECTION.getValue()));
double minEvictableIdleTime =
((BDecimal) poolRecord.get(HttpConstants.CONNECTION_POOLING_EVICTABLE_IDLE_TIME)).floatValue();
poolConfiguration.setMinEvictableIdleTime(minEvictableIdleTime < 0 ? 0 : (long) minEvictableIdleTime * 1000);

double timeBetweenEvictionRuns =
((BDecimal) poolRecord.get(HttpConstants.CONNECTION_POOLING_TIME_BETWEEN_EVICTION_RUNS)).floatValue();
poolConfiguration.setTimeBetweenEvictionRuns(
timeBetweenEvictionRuns < 0 ? 0 : (long) timeBetweenEvictionRuns * 1000);
}

private static int validateConfig(long value, String configName) {
Expand Down

0 comments on commit 12ea5e3

Please sign in to comment.