From b2b13409b55e778df8cb8d1890a453092e4e59e5 Mon Sep 17 00:00:00 2001
From: Erik Huelsmann <ehuels@gmail.com>
Date: Wed, 23 May 2018 23:20:36 +0200
Subject: [PATCH] * Add option to set the number of Starman workers

---
 README.md          |  8 ++++++++
 docker-compose.yml | 13 +++++++++++--
 start.sh           |  2 +-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 602b0e2..dcddc4f 100644
--- a/README.md
+++ b/README.md
@@ -129,6 +129,14 @@ Default: lsmb
 Set this if you want to automatically log in to a particular LedgerSMB database
 without needing to enter the name of that database on the login.pl login screen.
 
+## `LSMB_WORKERS`
+
+Default: 5
+
+Set this if you want to run in a memory-constrained environment. E.g. set it to
+2 when running in a 1 GB memory setup. Please do note that this may adversely
+affect the performance experience of users.
+
 ## Mail configuration
 
 The docker image uses `ssmtp` to send mail. 
diff --git a/docker-compose.yml b/docker-compose.yml
index 8c8cf5c..5e90501 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -32,7 +32,7 @@ services:
     networks:
       - internal
       - default
-    # The PORTS section below maps the LedgerSMB container port (5762)
+    # Uncomment the 'ports' section to map the LedgerSMB container port (5762)
     #  to the host's port of the same number, thus making LedgerSMB
     #  available on http://<host-dns-or-ip>:5762/
     #     SECURITY NOTE: Do this for evaluation purposes only!
@@ -40,7 +40,16 @@ services:
     #       and other sensitive data
     # ports:
     #   - "5762:5762"
-    # environment:
+    environment:
+      # The LSMB_WORKERS environment variable lets you select the number
+      # of processes serving HTTP requests. The default number of 2 workers
+      # is geared toward limited-memory situations (1 GB). In order to
+      # improve the performance experience, increase memory and the
+      # number of workers
+      #
+      LSMB_WORKERS: 2
+      #
+      #
       # SSMTP_ROOT:
       # SSMTP_HOSTNAME:
       # SSMTP_MAILHUB:
diff --git a/start.sh b/start.sh
index b8248a7..64bd228 100755
--- a/start.sh
+++ b/start.sh
@@ -45,4 +45,4 @@ echo "Selected PERL5LIB=$PERL5LIB";
 # --preload-app allows application initialization to kill the entire
 # starman instance (instead of just the worker, which will immediately
 # get restarted); it also has a positive effect on memory use
-exec starman --port 5762 --preload-app tools/starman.psgi
+exec starman --port 5762 --workers ${LSMB_WORKERS:-5} --preload-app tools/starman.psgi