<div dir="ltr">Hi Max,<div><br></div><div>    I&#39;ve integrated, but there&#39;s a conflict with the Cog sources because there&#39;s already support for RAW sockets in the Qwaq/Terf VM.  That means socket type 2 is already taken.  So I&#39;ve integrated like this:</div>
<div><br></div><div><div>#define TCPSocketType       0</div><div>#define UDPSocketType       1</div><div>#ifdef HAVE_SD_DAEMON</div><div># define ProvidedTCPSocketType  2</div><div># define RAWSocketType      3</div><div>
#else</div><div># define RAWSocketType      2</div><div>#endif</div></div><div><br></div><div>But I would prefer to integrate this:</div><div><br></div><div><div>#define TCPSocketType       0</div><div>#define UDPSocketType       1</div>
# define RAWSocketType      2<div>#define ProvidedTCPSocketType  3</div></div><div><br></div><div>Is it too late for you to change the Smalltalk code so that ProvidedTCPSocketType is 3?</div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Jul 8, 2014 at 7:08 AM, Max Leske <span dir="ltr">&lt;<a href="mailto:maxleske@gmail.com" target="_blank">maxleske@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 <br><div style="word-wrap:break-word"><div>Hi folks</div><div><br></div><div>As promised a long time ago my colleague Nik Lutz has finalized the patch for the VM that enables socket activation with Systemd. I will quickly go over what the patch is supposed to achieve, how we plan to use socket activation and what (minimal) changes are necessary.</div>
<div><br></div><br><div>Systemd Socket Activation:<br>Systemd opens a (network-) socket and waits for connections. When the first client connects the assotiated service (VM) is started. Systemd indicates via environment variable (LISTEN_FDS) that it opened a network socket.<br>
<font color="#0f61c8"><br></font>Detailed documentation on socket activation with Systemd can be found here: <a href="http://0pointer.de/blog/projects/socket-activation.html" target="_blank">http://0pointer.de/blog/projects/socket-activation.html</a></div>
<div><br></div><div><br></div><div>Our scenario for socket activation: </div><div>At Cmsbox we have hundereds of images running on a server, all of which listen on a dedicated network port for incoming connections. The server is powerful enough to run all these processes concurrently, especially since not every image receives requests all the time.</div>
<div>With socket activation we could further lower the server load and free up resources for images with a high request rate. Images that don’t receive any requests for a specified amount of time can be suspended automatically and reactivated when a request comes in.<br>
<br><br><br>The VM Patch:<br>The attached patch tries hard to be minimal. It defines a new socket type (ProvidedTCPSocketType) which you will also find in the image (Socket&gt;&gt;newSystemd). ProvidedTCPSocketType is special in that it can refer to an existing TCPSocket and does not necessarily entail the creation of a new socket.</div>
<div><br></div><div><br></div><div>The changes in the image:</div><div>- Socket&gt;&gt;newSystemd tries to open a new Systemd socket.</div><div>- TCPListener&gt;&gt;haveSystemdAssignedPort tests if the LISTEN_FDS environment variable has been set by Systemd for the current process.</div>
<div>- TCPListener&gt;&gt;primEnvironmentAtSymbol is a utility method that we need to check for the environment variable (IMPORTANT: copied from OSProcess; uses the OSProcess plugin)</div><div>- TCPListener&gt;&gt;pvtNewListener: has been modified to include the check for the Systemd port. If the socket has been assigned by Systemd, use a Systemd socket, a TCP socket otherwise</div>
<div><font color="#0f61c8"><br></font>Quick Howto:<br>- Adapt path to vm and image in pharo@.service<br>- Take a Seaside image and FileIn systemd.cs (tested with <a href="http://seaside.st/distributions/Seaside-2.8.4.zip" target="_blank">http://seaside.st/distributions/Seaside-2.8.4.zip</a>)<br>
- Save as 9999.image<br>- Copy pharo@.service and pharo@.socket to /etc/systemd/system<br>- As root run:<br> systemctl daemon-reload<br> systemctl start <a href="mailto:pharo@9999.socket" target="_blank">pharo@9999.socket</a><br>
- Open <a href="http://localhost:9999/seaside/config" target="_blank">http://localhost:9999/seaside/config</a><br><font color="#0f61c8"><br></font>[- systemctl stop <a href="mailto:pharo@9999.socket" target="_blank">pharo@9999.socket</a>]<br>
<font color="#0f61c8"><br></font>-&gt; Upon connection <a href="mailto:pharo@9999.socket" target="_blank">pharo@9999.socket</a> starts: <a href="mailto:pharo@9999.service" target="_blank">pharo@9999.service</a> (which would start .../9999.image)</div>
<div><br></div><div>You can see this in action in the following screencast: <a href="http://youtu.be/MVPLZNKg5j8" target="_blank">http://youtu.be/MVPLZNKg5j8</a></div><div><br></div><div><br></div><div>We hope that this patch (or some version of it) will find its way into the VM. If you have any questions please feel free to ask.</div>
<div><br></div><div><br></div><div>Cheers,</div><div>Max (on behalf of Nik and the rest of <a href="http://Netstyle.ch" target="_blank">Netstyle.ch</a>)<br><br><br><div></div></div></div><br><div style="word-wrap:break-word">
<div><div></div></div></div><br><div style="word-wrap:break-word"><div><div></div></div></div><br><div style="word-wrap:break-word"><div><div></div></div></div><br><div style="word-wrap:break-word"><div><div></div></div><br>
</div><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div>