[Pharo-dev] [DEV] Systemd socket activation patch for the VM

Max Leske maxleske at gmail.com
Tue Jul 8 10:08:01 EDT 2014


Hi folks

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.


Systemd Socket Activation:
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.

Detailed documentation on socket activation with Systemd can be found here: http://0pointer.de/blog/projects/socket-activation.html


Our scenario for socket activation: 
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.
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.



The VM Patch:
The attached patch tries hard to be minimal. It defines a new socket type (ProvidedTCPSocketType) which you will also find in the image (Socket>>newSystemd). ProvidedTCPSocketType is special in that it can refer to an existing TCPSocket and does not necessarily entail the creation of a new socket.


The changes in the image:
- Socket>>newSystemd tries to open a new Systemd socket.
- TCPListener>>haveSystemdAssignedPort tests if the LISTEN_FDS environment variable has been set by Systemd for the current process.
- TCPListener>>primEnvironmentAtSymbol is a utility method that we need to check for the environment variable (IMPORTANT: copied from OSProcess; uses the OSProcess plugin)
- TCPListener>>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

Quick Howto:
- Adapt path to vm and image in pharo at .service
- Take a Seaside image and FileIn systemd.cs (tested with http://seaside.st/distributions/Seaside-2.8.4.zip)
- Save as 9999.image
- Copy pharo at .service and pharo at .socket to /etc/systemd/system
- As root run:
 systemctl daemon-reload
 systemctl start pharo at 9999.socket
- Open http://localhost:9999/seaside/config

[- systemctl stop pharo at 9999.socket]

-> Upon connection pharo at 9999.socket starts: pharo at 9999.service (which would start .../9999.image)

You can see this in action in the following screencast: http://youtu.be/MVPLZNKg5j8


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.


Cheers,
Max (on behalf of Nik and the rest of Netstyle.ch)







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: systemd.cs
Type: application/octet-stream
Size: 1679 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment.cs>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pharo at .service
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment.service>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: squeak-svn.diff
Type: text/x-patch
Size: 1176 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment.diff>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment-0003.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pharo at .socket
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment.socket>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140708/641f970f/attachment-0004.html>


More information about the Pharo-dev mailing list