On Mon, 4 Dec 2000, Junfeng Zhang wrote:
> All the major operating systems should have POSIX threads implemented.
> Actually this can be configurable--multithreads or one thread.
I don't understand this. The OS can be configured for one thread? How
would that be any of use?
> Thread-only server is unsafe, I agree. Maybe the following model can be a
> little better. Several servers, each is multi-threaded. Every server can
> support a maximum number of requests simultaneously. If anything bad
> happends, it is limited to that server.
There is no difference. If anything bad happens with the current
multi-process server, all the postgres backends shutdown because the
shared memory may be corrupted.
> The cons side of processes model is not the startup time. It is about
> kernel resource and context-switch cost. Processes consume much more
> kernel resource than threads, and have a much higher cost for context
> switch. The scalability of threads model is much better than that of
> processes model.
What kernel resources do a process use? There is some VM mapping
overhead, a process table entry, and a file descriptor table. It is
possible to support thousands of processes today. For instance,
ftp.freesoftware.com supports up to 5000 FTP connections using a slightly
modified ftpd (doesn't use inetd anymore). That means with 5000 users
connected, that works out to 5000 processes active. Amazing but true.
Some OSes (Linux is the main one) implement threads as pseudo processes.
Linux threads are processes with a shared address space and file
descriptor table.
Context switch cost for threads can be lower if you are switching to a
thread in the same process. That of course assumes that all context
switches will occur within the same process, or the Linux
everything-is-a-process model isn't used.
> -Junfeng
Tom