Initial take on this and some comments: 
https://github.com/apache/james-project/pull/2380

Wojtek

On 18/08/2024 23:31, Benoit TELLIER wrote:
Hello Wojtek,

As expressed here [a], I overall share the diagnostic and analsis, and proposes 
to work on (1):
Parallelize the shutdown process. IE cheat on the guice wiring to
register Netty components, register them, and do this in parallel. Here
we need to be mindful that it do not mess up with the order of the
shutdown - which relies on listening the order of instanciation of Guice
  components.

[a] https://github.com/apache/james-project/pull/2373#issuecomment-2295396500
Graceful shutdown is important at least for IMAP as it prevents some 
inconsistencies on the distributed mailbox.

IMAP operation can be lengthy and to that end 2 seconds is not that much.

I'd rather keep the graceful shutdown as it is but make it less painful.

Thoughts?

--

Best regards,

Benoit TELLIER

General manager of Linagora VIETNAM.
Product owner for Team-Mail product.
Chairman of the Apache James project.

Mail: btell...@linagora.com
Tel: (0033) 6 77 26 04 58 (WhatsApp, Signal)


On Aug 17, 2024 6:02 PM, from Wojtek Hi,
(folloup to the PR comment: 
github.com/apache/james-project/pull/2373#issuecomment-2294855488)

As I found out the hard way, James takes a lot of time to perform 
clear/complete shutdown (log at
the end[1]).

As mentioned in the comment I see two main culprits:
1) `org.apache.james.protocols.lib.netty.AbstractServerFactory#destroy` 
destroys each server in
sequence - making it parallel by using parallel stream instead of for-loop in 
already cuts down
shutdown from 18s to 8
2) `is org.apache.james.protocols.netty.AbstractAsyncServer#unbind` with calls 
to
io.netty.util.concurrent.EventExecutorGroup#shutdownGracefully() - by default 
they use quiet period
of 2 seconds which makes each `.destroy()` call wait for 2 seconds which bumps 
the shutdown time.
Without that the shutdown is almost instant. I'm not sure that having this 
default couple of seconds
in this case makes sense as we are already in shutdown mode and unless services 
are closed first and
then the rest of the James waits for it being closed then this grace period 
could actually be
detrimental IMHO.




[1] Shutdown log
```
james-1  | [2024-08-17 13:01:42.855] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose Manage Sieve 
Service
james-1  | [2024-08-17 13:01:44.887] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose Manage Sieve 
Service done
james-1  | [2024-08-17 13:01:44.892] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service
james-1  | [2024-08-17 13:01:46.915] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service done
james-1  | [2024-08-17 13:01:46.915] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service
james-1  | [2024-08-17 13:01:48.940] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service done
james-1  | [2024-08-17 13:01:48.941] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service
james-1  | [2024-08-17 13:01:50.974] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service done
james-1  | [2024-08-17 13:01:50.974] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose SMTP Service
james-1  | [2024-08-17 13:01:52.998] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose POP3 Service
james-1  | [2024-08-17 13:01:55.033] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose POP3 Service done
james-1  | [2024-08-17 13:01:55.034] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose IMAP Service
james-1  | [2024-08-17 13:01:57.072] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose IMAP Service done
james-1  | [2024-08-17 13:01:57.073] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose IMAP Service
james-1  | [2024-08-17 13:01:59.100] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose IMAP Service done
james-1  | [2024-08-17 13:01:59.100] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose IMAP Service
james-1  | [2024-08-17 13:02:01.133] [INFO ] [            Thread-0]
o.a.j.p.l.n.AbstractConfigurableAsyncServer.destroy(): Dispose IMAP Service done
james-1  | [2024-08-17 13:02:01.157] [INFO ] [            Thread-0]
t.j.CONFIGURATION.lambda$main$0(): JAMES server STOPPPED in: 18.312s
```


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to