[Info-vax] Apache + mod_php performance

Dan Cross cross at spitfire.i.gajendra.net
Mon Oct 7 14:01:48 EDT 2024


In article <ve13ck$1pl4l$1 at dont-email.me>,
Mark Berryman  <mark at theberrymans.com> wrote:
>On 10/6/24 9:12 AM, Michael S wrote:
>> On Fri, 4 Oct 2024 17:43:02 -0000 (UTC)
>> cross at spitfire.i.gajendra.net (Dan Cross) wrote:
>> 
>>> In article <vdp8kn$a67s$1 at dont-email.me>,
>>> Dave Froble  <davef at tsoft-inc.com> wrote:
>>>> On 10/3/2024 7:00 PM, Chris Townley wrote:
>>>>> [snip]
>>>>> I don't remember George, but we have certainly woken up Dave! ;)
>>>>>
>>>>> and I am sure the troll is happy...
>>>>
>>>> I'm not sure whether I've been insulted?
>>>
>>> I suspect the "troll" reference is to Lawrence.  Sadly, Arne can
>>> not help himself when it comes to resisting arguing with that
>>> clown.
>> 
>> Troll or not, but the question about ability to pass open TCP socket to
>> child process (or, may be, to unrelated process) under VMS is a good
>> question.
>> As a lurker, I am waiting for the expert answer with interest.
>
>It is most definitely possible as that is precisely what the auxiliary 
>server in TCPIP Services does.  It listens for a connection, then 
>creates a process to handle it.  See the description of TCPIP$C_AUXS in 
>the TCPIP Services programming documentation.
>
>As Dave has mentioned, setting SO_SHARE on a socket would be another way 
>to accomplish this.

Neither of these sounds the same as descriptor passing over Unix
domain sockets on Unix/Linux; the auxiliary server sounds more
like `inetd`, in that there's some service that's listening and
accepting connections on some TCP/IP port, and then creating a
server to handle each incoming connection.

SO_SHARE is different again; it appears that the shared socket
must be created before the subprocesses that use it are created.
The Unix analogy would be a process that creates a listening
socket, and then fork's several processes that all `accept` on
that same socket (they will race one another as to which gets
to answer complete the `accept` for the next connection).  See
some example code at the bottom of this post; note this is
different from the earlier socket passing example I posted.

	- Dan C.

// Demonstration of a multiple processes accepting
// connections on the same bound listening socket.
//
// Dan Cross <cross at gajendra.net>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int
main(void)
{
	int sd, nsd;
	struct sockaddr_in sa;
	struct sockaddr_in client;
	socklen_t clientlen;
	pid_t pid;

	sd = socket(AF_INET, SOCK_STREAM, 0);
	if (sd < 0) {
		perror("socket");
		exit(EXIT_FAILURE);
	}
	memset(&sa, 0, sizeof sa);
	sa.sin_family = AF_INET;
	sa.sin_port = htons((unsigned short)8200);
	sa.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(sd, (struct sockaddr *)&sa, sizeof sa) < 0) {
		perror("bind");
		close(sd);
		exit(EXIT_FAILURE);
	}
	if (listen(sd, 255) < 0) {
		perror("listen");
		close(sd);
		exit(EXIT_FAILURE);
	}

	for (int k = 0; k < 3; k++) {
		pid = fork();
		if (pid < 0) {
			perror("fork");
			exit(EXIT_FAILURE);
		}
		if (pid > 0)  // Parent
			continue;
		// Child.
		pid = getpid();
		for (;;) {
			memset(&client, 0, sizeof client);
			clientlen = sizeof client;
			nsd = accept(sd, (struct sockaddr *)&client, &clientlen);
			if (nsd < 0) {
				perror("accept");
				close(sd);
				exit(EXIT_FAILURE);
			}
			printf("pid %d accepted a connection\n", pid);
			close(nsd);
		}
	}
	close(sd);
	for (int k = 0; k < 3; k++)
		wait(NULL);

	return EXIT_SUCCESS;
}


More information about the Info-vax mailing list