Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-06

Standby socket servers?

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Francisco Reyes

After reading the socket samples at
http://www.bastisoft.de/pascal/pasinet.html I am starting to get the basics of socket programming.

The one thing I don't see in that page is how one would have standby servers.

In other words I would like my server program to have some N number of daemons to handle the connection. Like one can do with apache..

Have a minimun number or processes always running with the ability to grow as needed up to a maximun number of processes.

I don't have exact numbers, but my guestimate is that during the busiest times of the day the program will need to handle 5 to 10 connections per second.

Reply by email

ik
to Francisco Reyes

Hi,

You can create a daemon is several ways, but here are two of them:
1. Create non blocking sockets for the server, and on every new communication open a new thread that will use that connection.
2. Create a non blocking sockets for the server, and on every new communication open a new process that will handle that connection.

I suggest that you open things by need, rather then by demand, because you never know how much connections you'll need, and if you'll only need one, and you will have 10, then it's "too much" for what you need.

Ido

Francisco Reyes wrote 16 lines
After reading the socket samples at http://www.bastisoft.de/pascal/pasinet.html I am starting to get the basics of socket programming. The one thing I don't see in that page is how one would have standby servers. In other words I would like my server program to have some N number of daemons to handle the connection. Like one can do with apache.. Have a minimun number or processes always running with the ability to grow as needed up to a maximun number of processes. I don't have exact numbers, but my guestimate is that during the busiest times of the day the program will need to handle 5 to 10 connections per second.

Reply by email

Francisco Reyes
to ik
ik wrote
You can create a daemon is several ways, but here are two of them: 1. Create non blocking sockets for the server, and on every new communication open a new thread that will use that connection.

Thread or fork?

2. Create a non blocking sockets for the server, and on every new communication open a new process that will handle that connection.

Do you know of any place, or sample code, that I can see how non blocking sockets work?

I suggest that you open things by need, rather then by demand, because you never know how much connections you'll need

I may do this during trial to get some numbers, but I am concerned that only having one instance and forking on demand will cause delays.

need one, and you will have 10, then it's "too much" for what you need.

I was thinking more along the lines of 2 to 5.
I am working on a postfix mail filter.
We process on our MX machines about 150K per machine (there are two of them).

That comes out to about 2 connections per second. However the distribution is not even. Most of the mail comes within 10 hours.

That turns out about 5 emails per second.

Reply by email

Alan Krause
to Francisco Reyes
Francisco Reyes wrote
Do you know of any place, or sample code, that I can see how non blocking sockets work?

Francisco,

The "bible" on this type of programming is Richard Steven's _Unix Network Programming_. I have both the old version of the book, as well as Volume 1 of the new and revised version.

Unfortunately, all of the code provided is written in C. However, it is a *very* thorough book and a looks at the many different ways of developing daemon applications, including pre-fork (favored on most Unix varieties) and pre-thread (favored on Windows platforms) varieties.

I *highly* recommend these books to anyone who want to do daemon programming on the Unix/Linux platform.

Show quoted text 12 lines
I may do this during trial to get some numbers, but I am concerned that only having one instance and forking on demand will cause delays. ... I was thinking more along the lines of 2 to 5. I am working on a postfix mail filter. We process on our MX machines about 150K per machine (there are two of them). That comes out to about 2 connections per second. However the distribution is not even. Most of the mail comes within 10 hours. That turns out about 5 emails per second.

I think the pre-fork method would be perfect for what you are describing as well.

Alan Krause

Reply by email

Francisco Reyes
to Alan Krause
Alan Krause wrote
The "bible" on this type of programming is Richard Steven's _Unix Network Programming_. I have both the old version of the book, as well as Volume 1 of the new and revised version.

Thanks.
Got it on Safari.
UNIX Network Programming Volume 1, Third Edition:
The Sockets Networking API
By W. Richard Stevens, Bill Fenner, Andrew M. Rudoff

I think the pre-fork method would be perfect for what you are describing as well.

Will read up on the book about that method.
Already found the chapter, 30, that has the different pre-fork models.

Thanks again for the pointer.
Have you implemented this method on any of your programs.. or you know of any sample code? Since you mention the samples in that book are in C..

Reply by email

Marco van de Voort
to Alan Krause: The "bible" on this type of programming is Richard Steven's _Unix Network Programming_. I…
Show quoted text 9 lines
Francisco Reyes wrote: > > Do you know of any place, or sample code, that I can see how non > blocking sockets work? Francisco, The "bible" on this type of programming is Richard Steven's _Unix Network Programming_. I have both the old version of the book, as well as Volume 1 of the new and revised version.

Aren't there three versions already? The original had the later "Advanced programming" volume as a mere chapter. In the second they are splitted, and the third is fairly recent, and by another author (R. W Stevens unfortunately passed away a few years back. A big loss for the programming books world)

Both Michael and I (the two of this did most of the dabbling in the Linux/Unix RTLs) have "Advanced..." and it is hightly recommended.

I also have the sockets book (splitted rev, the 2nd is about IPC) and the first volume of TCP/IP illustrated (which is also a good read)

Some of it is slightly outdated though, from before the newer threadmodels and KSE/EPoll of FreeBSD/Linux. I'm not sure how much this changed in more recent editions.

I picked up some of these fairly cheaply (they are normally Eur 40-50 ish, but e.g. I got the TCP/IP illustrated and the first socket book for 5 each) when the new editions emerged. It can be worthwhile to keep an eye out for these in yard sales etc.

Reply by email

Francisco Reyes
to Marco van de Voort
Marco van de Voort wrote
Aren't there three versions already? The original had the later "Advanced programming" volume as a mere chapter. In the second they are splitted, and the third is fairly recent

I don't think it will make much difference which version I got.. since the examples are in C. :-(

The concepts are very usefull and read the chapter yesterday, but ultimately what would be most helpfull would be some pascal samples. Otherwise I will just have to experiment and try to create the concept from the book in Pascal code.

Reply by email