simple-java-mail icon indicating copy to clipboard operation
simple-java-mail copied to clipboard

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

Open elalbertinoprimo opened this issue 11 months ago • 2 comments

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 ...". https://github.com/bbottema/simple-java-mail/blob/375bbd6211de25904cb46aba157258dbbe6032bb/modules/batch-module/src/main/java/org/simplejavamail/internal/batchsupport/BatchSupport.java#L84-L91
  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();
    }

elalbertinoprimo avatar Dec 09 '24 00:12 elalbertinoprimo

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!

bbottema avatar Dec 12 '24 12:12 bbottema

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

elalbertinoprimo avatar Dec 13 '24 12:12 elalbertinoprimo