Re: Apache hangs after having 6 x SSE streams active
Mark Hedges <[email protected]> Thu, 23 Oct 2025 09:00:50 -0700
| Newsgroups | gmane.comp.apache.mod-perl |
|---|---|
| Message-ID | <CAKGiyJuGGRc=B8S5VC-Z+dW-W1i+xYJaRN4Kwg551_FqzxJc9A@mail.gmail.com> |
--00000000000014d7db0641d58a67 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable PerlInterpScope handler use threads; # in loop: threads->yield(); ? On Thu, Oct 23, 2025, 08:43 Steven Haigh via modperl < [email protected]> wrote: > Hi all, > > I'm writing a web UI in perl + mod_perl that sends an SSE stream to the > browser full of JSON formatted updates etc. The browser then renders > that all via Javascript to the user. > > I've noticed that if I reload the page multiple times, or just navigate > away, when there's ~6 existing SSE streams, apache will stop accepting > new connections completely. > > I've hunted around via the normal search engines, turned up very little > - and out of desperation, asked ChatGPT's Codex... > > It suggested the following apache config: > > LoadModule mpm_event_module modules/mod_mpm_event.so > # Tune event MPM so we have headroom for long-lived SSE connections > <IfModule mpm_event_module> > ServerLimit 4 > StartServers 2 > MinSpareThreads 50 > MaxSpareThreads 150 > ThreadsPerChild 64 > MaxRequestWorkers 256 > MaxConnectionsPerChild 0 > </IfModule> > > ## Load mod_perl > LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so > PerlModule Apache2::Reload > PerlInitHandler Apache2::Reload > PerlOptions +Parent > PerlSwitches -Mlib=3D/usr/local/apache2/htdocs-includes > PerlInterpStart 20 > PerlInterpMinSpare 10 > PerlInterpMaxSpare 20 > PerlInterpMax 80 > > Even with this however, when I hit 6 x concurrent SSE streams being > served, Apache grinds to a halt and doesn't even load the > /server-status/ page for troubleshooting. > > Once some of the 'dead' SSE streams fail and those connections > terminated, apache starts behaving again. > > Has anyone come across this before and maybe knows a bit of additional > knowledge as to why this is, and what I can do about it? > > Thanks. > > -- > Steven Haigh > > =F0=9F=93=A7 [email protected] > =F0=9F=92=BB https://crc.id.au > > > --00000000000014d7db0641d58a67 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto">PerlInterpScope handler<div dir=3D"auto"><br></div><div d= ir=3D"auto"><br></div><div dir=3D"auto">use threads;</div><div dir=3D"auto"= ># in loop:</div><div dir=3D"auto">threads->yield();</div><div dir=3D"au= to"><br></div><div dir=3D"auto"><br></div><div dir=3D"auto">?</div></div><b= r><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class= =3D"gmail_attr">On Thu, Oct 23, 2025, 08:43 Steven Haigh via modperl <<a= href=3D"mailto:[email protected]">[email protected]</a>> wr= ote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px= 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br> <br> I'm writing a web UI in perl + mod_perl that sends an SSE stream to the= <br> browser full of JSON formatted updates etc. The browser then renders <br> that all via Javascript to the user.<br> <br> I've noticed that if I reload the page multiple times, or just navigate= <br> away, when there's ~6 existing SSE streams, apache will stop accepting = <br> new connections completely.<br> <br> I've hunted around via the normal search engines, turned up very little= <br> - and out of desperation, asked ChatGPT's Codex...<br> <br> It suggested the following apache config:<br> <br> LoadModule mpm_event_module modules/mod_mpm_event.so<br> # Tune event MPM so we have headroom for long-lived SSE connections<br> <IfModule mpm_event_module><br> =C2=A0 =C2=A0 =C2=A0ServerLimit=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 4<br> =C2=A0 =C2=A0 =C2=A0StartServers=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A02<br> =C2=A0 =C2=A0 =C2=A0MinSpareThreads=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A050<br> =C2=A0 =C2=A0 =C2=A0MaxSpareThreads=C2=A0 =C2=A0 =C2=A0 =C2=A0 150<br> =C2=A0 =C2=A0 =C2=A0ThreadsPerChild=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A064<br> =C2=A0 =C2=A0 =C2=A0MaxRequestWorkers=C2=A0 =C2=A0 =C2=A0 256<br> =C2=A0 =C2=A0 =C2=A0MaxConnectionsPerChild=C2=A0 =C2=A00<br> </IfModule><br> <br> ## Load mod_perl<br> LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so<br> PerlModule Apache2::Reload<br> PerlInitHandler Apache2::Reload<br> PerlOptions +Parent<br> PerlSwitches -Mlib=3D/usr/local/apache2/htdocs-includes<br> PerlInterpStart=C2=A0 =C2=A0 =C2=A0 20<br> PerlInterpMinSpare=C2=A0 =C2=A010<br> PerlInterpMaxSpare=C2=A0 =C2=A020<br> PerlInterpMax=C2=A0 =C2=A0 =C2=A0 =C2=A0 80<br> <br> Even with this however, when I hit 6 x concurrent SSE streams being <br> served, Apache grinds to a halt and doesn't even load the <br> /server-status/ page for troubleshooting.<br> <br> Once some of the 'dead' SSE streams fail and those connections <br> terminated, apache starts behaving again.<br> <br> Has anyone come across this before and maybe knows a bit of additional <br> knowledge as to why this is, and what I can do about it?<br> <br> Thanks.<br> <br> -- <br> Steven Haigh<br> <br> =F0=9F=93=A7 <a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"n= oreferrer">[email protected]</a><br> =F0=9F=92=BB <a href=3D"https://crc.id.au" rel=3D"noreferrer noreferrer" ta= rget=3D"_blank">https://crc.id.au</a><br> <br> <br> </blockquote></div> --00000000000014d7db0641d58a67--