Forráskód Böngészése

Dynamically determine concurrency based on memory

Girish Ramakrishnan 7 éve
szülő
commit
3c2153fc20
3 módosított fájl, 10 hozzáadás és 2 törlés
  1. 2 1
      Dockerfile
  2. 1 1
      apache/mpm_prefork.conf
  3. 7 0
      start.sh

+ 2 - 1
Dockerfile

@@ -32,7 +32,8 @@ RUN chown -R www-data:www-data /app/code
 # configure apache
 RUN rm /etc/apache2/sites-enabled/*
 RUN sed -e 's,^ErrorLog.*,ErrorLog "|/bin/cat",' -i /etc/apache2/apache2.conf
-COPY apache/mpm_prefork.conf /etc/apache2/mods-available/mpm_prefork.conf
+COPY apache/mpm_prefork.conf /etc/apache2/mods-available/mpm_prefork.conf.template
+RUN ln -sf /run/wordpress/mpm_prefork.conf /etc/apache2/mods-available/mpm_prefork.conf
 
 RUN a2disconf other-vhosts-access-log
 ADD apache/wordpress.conf /etc/apache2/sites-enabled/wordpress.conf

+ 1 - 1
apache/mpm_prefork.conf

@@ -9,7 +9,7 @@
 	MaxSpareServers 3
 
     # Maximum number of servers at any given instant. Requests will be queued after this
-	MaxRequestWorkers	  150
+	MaxRequestWorkers	  6
 
     # Recycle process after handling these many requests. This protected against accidental memory leaks
 	MaxConnectionsPerChild   100

+ 7 - 0
start.sh

@@ -29,6 +29,13 @@ sed -e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/" \
     -e "s/##TABLE_PREFIX/${table_prefix}/" \
     /app/code/wp-config.php.template > /run/wordpress/wp-config.php # sed -i seems to destroy symlink
 
+# Generate pre-fork configuration
+memory_limit=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) # this is the RAM. we have equal amount of swap
+concurrency=$((memory_limit*2/1024/1024/40)) # wp has 40MB limit
+
+echo "Setting max requests to ${concurrency}"
+sed -e "s/MaxRequestWorkers.*/MaxRequestWorkers ${concurrency}/" /etc/apache2/mods-available/mpm_prefork.conf.template > /run/wordpress/mpm_prefork.conf
+
 # Used for wp rewrite
 touch /app/data/htaccess