Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different corePoolSize for different Mailer instances (with using batch module) #565

Open
elalbertinoprimo opened this issue Dec 9, 2024 · 2 comments

Comments

@elalbertinoprimo
Copy link

elalbertinoprimo commented Dec 9, 2024

I am trying to configure different corePoolSize for 2 Mailer instances, but so far without success. As i understand from documentation, all i need is to define different clusterKey for each Mailer. But it doesn`t work as I expect. I also use batch-module.

  1. new SmtpConnectionPoolClustered beeing created here just for 1st Mailer. For 2nd I am getting warning "Global SMTP Connection pool is already configured with pool defaults ...".
    private void ensureClusterInitialized(@NotNull OperationalConfig operationalConfig) {
    if (smtpConnectionPool == null) {
    LOGGER.warn("Starting SMTP connection pool cluster: JVM won't shutdown until the pool is manually closed with mailer.shutdownConnectionPool() (for each mailer in the cluster)");
    smtpConnectionPool = new SmtpConnectionPoolClustered(configureSmtpClusterConfig(operationalConfig));
    } else if (compareClusterConfig(operationalConfig, smtpConnectionPool.getClusterConfig())) {
    LOGGER.warn("Global SMTP Connection pool is already configured with pool defaults from the first Mailer instance, ignoring relevant properties from {}", operationalConfig);
    }
    }
  2. So there is just one instance of ResourceClusters created with clusterConfig (including corePoolSize) from 1st MailerBuilder cofig. Then it`s beeing reused for 2nd cluster as well.
    https://github.com/bbottema/clustered-object-pool/blob/5857ced611c5be3489cd3cb763bfce8421aab9d9/src/main/java/org/bbottema/clusteredobjectpool/core/ResourceClusters.java#L55

My config:

    @Bean(name = FIRST_SERVER_HOST)
    public Mailer mailerFirst() {
        return MailerBuilder
                .withSMTPServer(FIRST_SERVER_HOST, FIRST_SERVER_PORT)
                .async()
                .withThreadPoolSize(20)
                .withConnectionPoolCoreSize(1)
                .withClusterKey(UUID.randomUUID())
                .buildMailer();
    }

    @Bean(name = SECOND_SERVER_HOST)
    public Mailer mailerSecond() {
        return MailerBuilder
                .withSMTPServer(SECOND_SERVER_HOST, SECOND_SERVER_PORT)
                .async()
                .withThreadPoolSize(20)
                .withConnectionPoolCoreSize(0)
                .withClusterKey(UUID.randomUUID())
                .buildMailer();
    }
@bbottema
Copy link
Owner

Hello!

There are some properties that are considered globally applicable (as defaults) for all clusters and cannot be changed after the initial registration. These are:

  • connection pool core size
  • connection pool max size
  • load balancing strategy
  • expiration policy

The properties that can be provided differently per cluster are:

  • connection pool claim timeout

If this doesn't work for you, please let me know your use case. Also, it would help me to know which part of the documentation wasn't clear enough so I can improve it. Thanks!

@elalbertinoprimo
Copy link
Author

Hello! Thank you for reply.

In my case we work with 2 SMTP-servers, one of which has a problem with handling a large number of open connections. So I would like to set a different value "connection pool core size" for it (0).

Regarding documentation, "(core size, max size etc.) are set and fixed by the first Mailer instance in the cluster " made me think that i can configure it different way for different clusters.
https://www.simplejavamail.org/configuration.html#section-batch-and-clustering:~:text=Note%202%3A-,The%20Connection%20Pool%20defaults%20(core%20size%2C%20max%20size%20etc.)%20are%20set%20and%20fixed%20by%20the%20first%20Mailer%20instance%20in%20the%20cluster.,-Subsequent%20Mailer%20instances

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants