<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>scale Archives - gj</title>
	<atom:link href="https://blog.gaiterjones.com/tag/scale/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/tag/scale/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Thu, 14 Feb 2019 12:58:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Docker Mono Host Magento 2 Service Scaling and Dynamic Load Balancing with VARNISH</title>
		<link>https://blog.gaiterjones.com/docker-mono-host-magento-2-service-scaling-and-dynamic-load-balancing-with-varnish/</link>
					<comments>https://blog.gaiterjones.com/docker-mono-host-magento-2-service-scaling-and-dynamic-load-balancing-with-varnish/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Sun, 18 Jun 2017 16:30:30 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[Magento2]]></category>
		<category><![CDATA[Scaled Services]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[magento2]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[varnish]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1674</guid>

					<description><![CDATA[As I started building Docker service container images for Magento 2 CE development I got interested in the concept of dynamic service load balancing on a single host. Having already...<a class="more-link" href="https://blog.gaiterjones.com/docker-mono-host-magento-2-service-scaling-and-dynamic-load-balancing-with-varnish/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>As I started building <a href="https://blog.gaiterjones.com/docker-magento-2-development-deployment-php7-apache2-4-redis-varnish-scaleable/">Docker service container images for Magento 2</a> CE development I got interested in the concept of dynamic service load balancing on a single host. Having already created a <a href="https://blog.gaiterjones.com/docker-mono-host-service-scaling-and-dynamic-load-balancing-with-nginx/">dynamic load balancer using NGINX</a> I wanted to do the same for Magento 2 using <strong>Varnish</strong>.</p>
<p>My Magento 2 service container images include REDIS services for the Magento session and system cache and a Varnish service for the full page cache. Varnish is an HTTP accelerator designed for content-heavy dynamic web sites and is the recommended full page cache system for Magento 2.</p>
<figure id="attachment_1690" aria-describedby="caption-attachment-1690" style="width: 1280px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2017/06/magento2-docker-network.png" alt="" width="1280" height="1024" class="size-full wp-image-1690" /><figcaption id="caption-attachment-1690" class="wp-caption-text">Magento 2 Docker Network</figcaption></figure>
<p>Varnish is configured via the Varnish Configuration Language (VCL) config file. By configuring multiple backend servers in VCL and grouping them into a director we can create a Varnish <a href="https://varnish-cache.org/docs/trunk/users-guide/vcl-backends.html">load balancer</a>.</p>
<span class="collapseomatic collapse" id="id661341955896a"  tabindex="0" title="Varnish Magento 2 load balancing VCL"    >Varnish Magento 2 load balancing VCL</span><div id="target-id661341955896a" class="collapseomatic_content ">
<pre>[text]
backend magento2_php_apache_1 {
.host = &quot;x.x.x.2&quot;;
.port = &quot;80&quot;;
.probe = {.request =
&quot;GET /healthcheck.php HTTP/1.1&quot; &quot;Host: magento2.gaiterjones.com&quot; &quot;Connection: close&quot; &quot;Accept: text/html&quot;;.timeout = 1s;.interval = 30s;.window = 10;.threshold = 8;}
}
backend magento2_php_apache_2 {
.host = &quot;x.x.x.8&quot;;
.port = &quot;80&quot;;
.probe = {.request =
&quot;GET /healthcheck.php HTTP/1.1&quot; &quot;Host: magento2.gaiterjones.com&quot; &quot;Connection: close&quot; &quot;Accept: text/html&quot;;.timeout = 1s;.interval = 30s;.window = 10;.threshold = 8;}
}
backend magento2_php_apache_3 {
.host = &quot;x.x.x.10&quot;;
.port = &quot;80&quot;;
.probe = {.request =
&quot;GET /healthcheck.php HTTP/1.1&quot; &quot;Host: magento2.gaiterjones.com&quot; &quot;Connection: close&quot; &quot;Accept: text/html&quot;;.timeout = 1s;.interval = 30s;.window = 10;.threshold = 8;}
}
backend magento2_php_apache_4 {
.host = &quot;x.x.x.11&quot;;
.port = &quot;80&quot;;
.probe = {.request =
&quot;GET /healthcheck.php HTTP/1.1&quot; &quot;Host: magento2.gaiterjones.com&quot; &quot;Connection: close&quot; &quot;Accept: text/html&quot;;.timeout = 1s;.interval = 30s;.window = 10;.threshold = 8;}
}
backend magento2_php_apache_5 {
.host = &quot;x.x.x.9&quot;;
.port = &quot;80&quot;;
.probe = {.request =
&quot;GET /healthcheck.php HTTP/1.1&quot; &quot;Host: magento2.gaiterjones.com&quot; &quot;Connection: close&quot; &quot;Accept: text/html&quot;;.timeout = 1s;.interval = 30s;.window = 10;.threshold = 8;}
}
sub vcl_init {
new cluster1 = directors.round_robin();
cluster1.add_backend(magento2_php_apache_1);
cluster1.add_backend(magento2_php_apache_2);
cluster1.add_backend(magento2_php_apache_3);
cluster1.add_backend(magento2_php_apache_4);
cluster1.add_backend(magento2_php_apache_5);
}
[/text]</pre>
</div>
<h2>Scale Manager</h2>
<p>I use a service container called <em>php-apache</em> to run the Magento core code. Docker compose allows you to scale containers on a single host, so for example with the command</p>
<p><em>docker-compose scale php-apache=5</em></p>
<p>I can quickly scale the Magento2 php-apache service up to 5 containers, that is 5 instances of the php-apache service running the Magento2 core php code and apache web server.</p>
<p>The scale manager service monitors docker processes and detects when the php-apache service is scaled up or down. When a change is detected it dynamically creates the VCL configuration required to tell Varnish about the changes and applies these to the Varnish server.</p>
<figure id="attachment_1676" aria-describedby="caption-attachment-1676" style="width: 500px" class="wp-caption aligncenter"><img decoding="async" style="padding: 1px; border: 1px solid #021a40;" src="https://blog.gaiterjones.com/wp-content/uploads/2017/06/magento2-scale-demo.jpg" alt="" width="500" height="487" class="size-full wp-image-1676" /><figcaption id="caption-attachment-1676" class="wp-caption-text">Magento 2 Scale Demo</figcaption></figure>
<h2>Magento 2 Scale Demo</h2>
<p>In the video below I start with one running instance of the Magento 2 service, I then scale the service up to 5 and using the scale demo page (which is not cached by Varnish) on my <a href="http://magento2.gaiterjones.com/">Magento 2 dev site</a> to analyse the scale manager output data and display the running Magento 2 service containers.</p>
<p>As I refresh the page the Magento 2 container rendering the page is highlighted in yellow. you can see how Varnish round robins between the 5 available containers. Finally I scale the service back down and manually update the Varnish server config via the command line php script on the manager.</p>
<p>Another way to see the round robin connection distribution from varnish is to load up a <em>phpinfo()</em> page, you will see the SERVER_ADDR variable changing with each container that processes the request.</p>
<p><img decoding="async" src="https://blog.gaiterjones.com/dropbox/docker-magento2-scaledemox2.gif" alt="docker scale service dynamic load balancing with nginx demo video" class="aligncenter" /></p>
<p>Would you actually run 5 Magento 2 php-apache services? Good question! For true resilience and load balancing you would need multiple hosts and a Docker swarm. Multiple service containers on a single host do at least provide a simple level of redundancy and host server load balancing, I would definitely consider using it in production especially with a multi core server.</p>
<p>Many thanks to <a href="https://github.com/fballiano/docker-magento2">Fabrizio Balliano</a> for the inspiration and assistance.</p>
<p>See <a href="https://blog.gaiterjones.com/docker-magento-2-development-deployment-php7-apache2-4-redis-varnish-scaleable/">this post</a> for instructions on how to deploy this Magento 2 development environment.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/docker-mono-host-magento-2-service-scaling-and-dynamic-load-balancing-with-varnish/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
