You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2022/04/18 04:38:15 UTC
[GitHub] [james-project] vttranlina commented on a diff in pull request #964: JAMES-3747 + JAMES-3749 Metrics and configuration options for RabbitMQ...
vttranlina commented on code in PR #964:
URL: https://github.com/apache/james-project/pull/964#discussion_r851866249
##########
backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java:
##########
@@ -660,11 +661,13 @@ public int getMaxChannel() {
private final Configuration configuration;
private final InstrumentedPool<? extends Channel> newPool;
+ private final MetricFactory metricFatcory;
Review Comment:
metricFatcory -> metricFactory
##########
backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java:
##########
@@ -700,26 +652,47 @@ public int getMaxChannel() {
}
private static final Logger LOGGER = LoggerFactory.getLogger(ReactorRabbitMQChannelPool.class);
- private static final long MAXIMUM_BORROW_TIMEOUT_IN_MS = Duration.ofSeconds(5).toMillis();
private static final int MAX_CHANNELS_NUMBER = 3;
private static final int MAX_BORROW_RETRIES = 3;
- private static final Duration MIN_BORROW_DELAY = Duration.ofMillis(50);
+ private static final Duration MAX_BORROW_DELAY = Duration.ofSeconds(30);
+ private final ConcurrentHashMap<Integer, PooledRef<? extends Channel>> refs = new ConcurrentHashMap<>();
private final Mono<Connection> connectionMono;
- private final GenericObjectPool<Channel> pool;
- private final ConcurrentSkipListSet<Channel> borrowedChannels;
private final Configuration configuration;
+
+ private final InstrumentedPool<? extends Channel> newPool;
+ private final MetricFactory metricFatcory;
private Sender sender;
- public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration) {
+ public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration, MetricFactory metricFatcory) {
this.connectionMono = connectionMono;
this.configuration = configuration;
- ChannelFactory channelFactory = new ChannelFactory(connectionMono, configuration);
+ this.metricFatcory = metricFatcory;
+
+ newPool = PoolBuilder.from(connectionMono
+ .flatMap(this::openChannel))
+ .sizeBetween(1, configuration.maxChannel)
+ .maxPendingAcquireUnbounded()
+ .evictionPredicate((channel, metadata) -> {
+ if (!channel.isOpen()) {
+ return true;
+ }
+ if (metadata.idleTime() > Duration.ofSeconds(30).toMillis()) {
+ return true;
+ }
+ return false;
+ })
+ .destroyHandler(channel -> Mono.fromRunnable(Throwing.runnable(channel::close)))
+ .buildPool();
+ }
- GenericObjectPoolConfig<Channel> config = new GenericObjectPoolConfig<>();
- config.setMaxTotal(configuration.getMaxChannel());
- this.pool = new GenericObjectPool<>(channelFactory, config);
- this.borrowedChannels = new ConcurrentSkipListSet<>(Comparator.comparingInt(System::identityHashCode));
+ private Mono<? extends Channel> openChannel(Connection connection) {
+ return Mono.fromCallable(connection::openChannel)
+ .map(maybeChannel ->
+ maybeChannel.orElseThrow(() -> new RuntimeException("RabbitMQ reached to maximum opened channels, cannot get more channels")))
Review Comment:
`"RabbitMQ reached to maximum opened channels, cannot get more channels"`
It may be a not correct message at all? How we can ensure empty option only come from "reached to maximum"?
##########
backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java:
##########
@@ -700,26 +652,47 @@ public int getMaxChannel() {
}
private static final Logger LOGGER = LoggerFactory.getLogger(ReactorRabbitMQChannelPool.class);
- private static final long MAXIMUM_BORROW_TIMEOUT_IN_MS = Duration.ofSeconds(5).toMillis();
private static final int MAX_CHANNELS_NUMBER = 3;
private static final int MAX_BORROW_RETRIES = 3;
- private static final Duration MIN_BORROW_DELAY = Duration.ofMillis(50);
+ private static final Duration MAX_BORROW_DELAY = Duration.ofSeconds(30);
+ private final ConcurrentHashMap<Integer, PooledRef<? extends Channel>> refs = new ConcurrentHashMap<>();
private final Mono<Connection> connectionMono;
- private final GenericObjectPool<Channel> pool;
- private final ConcurrentSkipListSet<Channel> borrowedChannels;
private final Configuration configuration;
+
+ private final InstrumentedPool<? extends Channel> newPool;
+ private final MetricFactory metricFatcory;
private Sender sender;
- public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration) {
+ public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration, MetricFactory metricFatcory) {
this.connectionMono = connectionMono;
this.configuration = configuration;
- ChannelFactory channelFactory = new ChannelFactory(connectionMono, configuration);
+ this.metricFatcory = metricFatcory;
+
+ newPool = PoolBuilder.from(connectionMono
+ .flatMap(this::openChannel))
+ .sizeBetween(1, configuration.maxChannel)
+ .maxPendingAcquireUnbounded()
+ .evictionPredicate((channel, metadata) -> {
+ if (!channel.isOpen()) {
+ return true;
+ }
+ if (metadata.idleTime() > Duration.ofSeconds(30).toMillis()) {
Review Comment:
```suggestion
if (metadata.idleTime() > configuration.maxBorrowDelay.toMillis()) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org