You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Steven Haigh via modperl <mo...@perl.apache.org> on 2025/10/23 15:41:45 UTC

Apache hangs after having 6 x SSE streams active

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=/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

📧 netwiz@crc.id.au
💻 https://crc.id.au



Re: Apache hangs after having 6 x SSE streams active

Posted by "Edward J. Sabol" <ed...@gmail.com>.
Mod_perl won't work with mpm_event and threads unless you compile Perl with specific options and avoid doing certain things which can cause segmentation faults in Perl. You can't just use an "off-the-shelf" version of Perl. Search the mod_perl mailing list archives for posts by Joe Schaefer going back over the past ~3 years for clues on how to do that and check out his sealed.pm module. I haven't done it or used it personally. It sounds non-trivial to set up properly. If you try going down this route, please report back with your findings.

According to conventional wisdom, mpm_prefork works better (or at least easier) for mod_perl and is often recommended for mod_perl. Most mod_perl developers avoid using threads entirely because the combination of mod_perl and threads is so problematic. Mpm_prefork is less efficient than mpm_event by most accounts, of course. You would certainly need to configure Apache to have way more than 4 servers with mpm_prefork.

Good luck,
Ed

> On Oct 23, 2025, at 11:42 AM, Steven Haigh via modperl <mo...@perl.apache.org> wrote:
> 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=/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?


Re: Apache hangs after having 6 x SSE streams active

Posted by Mark Hedges <th...@gmail.com>.
PerlInterpScope handler


use threads;
# in loop:
threads->yield();


?

On Thu, Oct 23, 2025, 08:43 Steven Haigh via modperl <
modperl@perl.apache.org> 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=/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
>
> 📧 netwiz@crc.id.au
> 💻 https://crc.id.au
>
>
>