From 56038fab049423ad5defa1f2ad39adcf5fab34e6 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 19 Nov 2026 15:00:12 +0200 Subject: [PATCH 1/6] Enabled gzip compression for Mission Portal responses JavaScript, CSS and JSON were sent uncompressed. Mission Portal loads several megabytes of JavaScript per page. Ticket: ENT-15000 Changelog: None --- cfe_internal/enterprise/templates/httpd.conf.mustache | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cfe_internal/enterprise/templates/httpd.conf.mustache b/cfe_internal/enterprise/templates/httpd.conf.mustache index 110df691de..e69bf29b9c 100644 --- a/cfe_internal/enterprise/templates/httpd.conf.mustache +++ b/cfe_internal/enterprise/templates/httpd.conf.mustache @@ -252,6 +252,11 @@ LogLevel warn # Timeout defaults to 60 but that is too short for some operations on slower hub hardware Timeout 120 +# Compress text responses, Mission Portal loads several megabytes of JavaScript per page +LoadModule filter_module modules/mod_filter.so +LoadModule deflate_module modules/mod_deflate.so +AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json image/svg+xml + {{#classes.mission_portal_http2_enabled}} # Use mod_http2 LoadModule http2_module modules/mod_http2.so From 04ed29bf7a03d3f6d7d7de47216c6bb7a7f38bac Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 19 Nov 2026 15:00:12 +0200 Subject: [PATCH 2/6] Added browser caching headers for Mission Portal static files Combined bundles in tmp/ are renamed when their content changes, so they can be cached permanently. Fonts and images are cached for a week. Ticket: ENT-15000 Changelog: None --- cfe_internal/enterprise/templates/httpd.conf.mustache | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cfe_internal/enterprise/templates/httpd.conf.mustache b/cfe_internal/enterprise/templates/httpd.conf.mustache index e69bf29b9c..df7351ce70 100644 --- a/cfe_internal/enterprise/templates/httpd.conf.mustache +++ b/cfe_internal/enterprise/templates/httpd.conf.mustache @@ -257,6 +257,16 @@ LoadModule filter_module modules/mod_filter.so LoadModule deflate_module modules/mod_deflate.so AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json image/svg+xml + + # Carabiner bundles in tmp/ get a new name whenever a source file changes + + Header set Cache-Control "public, max-age=31536000, immutable" + + + Header set Cache-Control "public, max-age=604800" + + + {{#classes.mission_portal_http2_enabled}} # Use mod_http2 LoadModule http2_module modules/mod_http2.so From 0cae424f5cea8f9ab147c2bbb1ca795791b2ca90 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Fri, 20 Nov 2026 18:02:14 +0200 Subject: [PATCH 3/6] php-fpm on the hub listens on a unix socket instead of port 9000 A socket file cannot clash with another service on the port, and only Apache's user can connect to it. Ticket: ENT-15000 Changelog: None --- cfe_internal/enterprise/templates/httpd.conf.mustache | 2 +- cfe_internal/enterprise/templates/php-fpm.conf.mustache | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cfe_internal/enterprise/templates/httpd.conf.mustache b/cfe_internal/enterprise/templates/httpd.conf.mustache index df7351ce70..8567141460 100644 --- a/cfe_internal/enterprise/templates/httpd.conf.mustache +++ b/cfe_internal/enterprise/templates/httpd.conf.mustache @@ -279,7 +279,7 @@ LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so # Need to pass auth headers to fpm SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 -SetHandler "proxy:fcgi://127.0.0.1:9000" +SetHandler "proxy:unix:{{{vars.sys.workdir}}}/httpd/php-fpm.sock|fcgi://localhost" {{/classes.mission_portal_http2_enabled}} {{^classes.mission_portal_http2_enabled}} diff --git a/cfe_internal/enterprise/templates/php-fpm.conf.mustache b/cfe_internal/enterprise/templates/php-fpm.conf.mustache index 3a1ba166b4..67064963fe 100644 --- a/cfe_internal/enterprise/templates/php-fpm.conf.mustache +++ b/cfe_internal/enterprise/templates/php-fpm.conf.mustache @@ -179,7 +179,7 @@ group = cfapache ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = 127.0.0.1:9000 +listen = {{{vars.sys.workdir}}}/httpd/php-fpm.sock ; Set listen(2) backlog. ; Default Value: 511 (-1 on Linux, FreeBSD and OpenBSD) @@ -194,6 +194,9 @@ listen = 127.0.0.1:9000 ;listen.owner = nobody ;listen.group = nobody ;listen.mode = 0660 +listen.owner = cfapache +listen.group = cfapache +listen.mode = 0660 ; When POSIX Access Control Lists are supported you can set them using ; these options, value is a comma separated list of user/group names. From 49012939956a6bf1d168e5a2dd9d7d4148477384 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 19 Nov 2026 20:27:05 +0200 Subject: [PATCH 4/6] Mission Portal API runs in its own php-fpm pool on the hub Mission Portal requests wait on loopback requests to the API. With one shared pool, all workers could end up waiting for API requests that had no free worker left, and the hub stopped responding until the proxy timeout. Requests under /api now go to a separate pool. Ticket: ENT-15000 Changelog: None --- .../enterprise/templates/httpd.conf.mustache | 7 +++++++ .../enterprise/templates/php-fpm.conf.mustache | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cfe_internal/enterprise/templates/httpd.conf.mustache b/cfe_internal/enterprise/templates/httpd.conf.mustache index 8567141460..f8f30a1cbb 100644 --- a/cfe_internal/enterprise/templates/httpd.conf.mustache +++ b/cfe_internal/enterprise/templates/httpd.conf.mustache @@ -324,6 +324,13 @@ AddType application/x-httpd-php-source php{{{vars.cfe_internal_hub_vars.php_v RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.php [QSA,L] +{{#classes.mission_portal_http2_enabled}} + + # Mission Portal requests wait on API requests, so the API gets its own php-fpm pool. + + SetHandler "proxy:unix:{{{vars.sys.workdir}}}/httpd/php-fpm-api.sock|fcgi://localhost" + +{{/classes.mission_portal_http2_enabled}} diff --git a/cfe_internal/enterprise/templates/php-fpm.conf.mustache b/cfe_internal/enterprise/templates/php-fpm.conf.mustache index 67064963fe..8103351a52 100644 --- a/cfe_internal/enterprise/templates/php-fpm.conf.mustache +++ b/cfe_internal/enterprise/templates/php-fpm.conf.mustache @@ -635,3 +635,18 @@ access.log = {{{vars.sys.workdir}}}/httpd/logs/www-pool.access.log ;php_admin_value[error_log] = /var/log/fpm-php.www.log ;php_admin_flag[log_errors] = on ;php_admin_value[memory_limit] = 32M + +; Mission Portal workers wait on loopback API requests. With one shared pool, all workers can end up +; waiting for API requests that have no free worker left, so the API runs in its own pool. +[api] +user = cfapache +group = cfapache +listen = {{{vars.sys.workdir}}}/httpd/php-fpm-api.sock +listen.owner = cfapache +listen.group = cfapache +listen.mode = 0660 +pm = dynamic +pm.max_children = {{{max_children}}} +pm.start_servers = {{{start_servers}}} +pm.min_spare_servers = {{{min_spare_servers}}} +pm.max_spare_servers = {{{max_spare_servers}}} From 34ebbacb969969ed0f92f4ab608a30222dc84188 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 19 Nov 2026 20:27:49 +0200 Subject: [PATCH 5/6] php-fpm pool size on the hub is also capped by the number of CPU cores pm.max_children was derived from memory only, e.g. 190 workers on a 2-core hub with 8 GB RAM. Under load that overloaded the CPU and held up to 250 PostgreSQL connections without more throughput. The pool is now limited to 12 workers per core as well, def.php_fpm_www_pool_* still overrides it. Ticket: ENT-15000 Changelog: None --- cfe_internal/enterprise/mission_portal.cf | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cfe_internal/enterprise/mission_portal.cf b/cfe_internal/enterprise/mission_portal.cf index 665c8f457e..c420214fb7 100644 --- a/cfe_internal/enterprise/mission_portal.cf +++ b/cfe_internal/enterprise/mission_portal.cf @@ -70,7 +70,7 @@ bundle agent cfe_internal_enterprise_mission_portal "fpm_children_average_memory_kb" int => "25600"; # average memory taken by one fpm process 25MB * 1024 - "php_fpm_www_pool_max_children_calculated" + "php_fpm_www_pool_max_children_by_memory" int => int( ifelse( isvariable("mem_total_kb"), @@ -81,6 +81,28 @@ bundle agent cfe_internal_enterprise_mission_portal ) ); + # More workers than this per CPU core only add CPU contention and database connections. + "php_fpm_www_pool_max_children_by_cpu" + int => int( + ifelse( + isvariable("cpu_cores_number"), + eval("$(cpu_cores_number) * 12"), + "60" + ) + ); + + "php_fpm_www_pool_max_children_calculated" + int => int( + ifelse( + isgreaterthan( + "$(php_fpm_www_pool_max_children_by_memory)", + "$(php_fpm_www_pool_max_children_by_cpu)" + ), + "$(php_fpm_www_pool_max_children_by_cpu)", + "$(php_fpm_www_pool_max_children_by_memory)" + ) + ); + "php_fpm_pid_file" string => "$(sys.workdir)/httpd/php-fpm.pid"; "php_fpm_www_pool_max_children" From ad8046ca5f6a95763707110d4279916c23c9a257 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 19 Nov 2026 21:08:19 +0200 Subject: [PATCH 6/6] Hub serves the Mission Portal API over plain HTTP to localhost Mission Portal calls the local API on every request. Outside the HTTPS virtual host, /api is now served only to localhost and marked as HTTPS, since those requests are made on behalf of HTTPS clients. Other clients are still refused. Ticket: ENT-15000 Changelog: None --- .../enterprise/templates/httpd.conf.mustache | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cfe_internal/enterprise/templates/httpd.conf.mustache b/cfe_internal/enterprise/templates/httpd.conf.mustache index f8f30a1cbb..4d78607672 100644 --- a/cfe_internal/enterprise/templates/httpd.conf.mustache +++ b/cfe_internal/enterprise/templates/httpd.conf.mustache @@ -313,6 +313,18 @@ AddType application/x-httpd-php-source php{{{vars.cfe_internal_hub_vars.php_v +# Mission Portal calls the local API over plain HTTP to avoid TLS on every request. Outside the HTTPS +# virtual host /api is only served to localhost, and those requests act for HTTPS clients. +Alias "/api" "{{{vars.cfe_internal_hub_vars.docroot}}}/api" + + + Require all denied + + + SetEnvIf Remote_Addr "^(127\.0\.0\.1|::1)$" HTTPS=on + + + Order deny,allow