Jeez, Jim, pick an address! :)
Brian
---------- Forwarded message ----------
From: Jim Jagielski <jim@shado.jaguNET.com>
Subject: Additional serialization code
To: new-httpd@hyperreal.com
Date: Mon, 7 Aug 1995 19:21:45 -0400 (EDT)
As mentioned in a previous message, although the concept of serializing
accept() is _very_ code, for some systems and setups, the use of fcntl()
to perform the lock may not be the best idea, since it's implementation
of fcntl() locking (esp. under NFS) can take an appreciable amount of
time.
I've added another possible option: FLOCK_SERIALIZED_ACCEPT. Basically,
it simply uses flock() instead of fcntl(). Now, of course, if the server
and the log file are on different machines, then flock() won't work and
fcntl() is the way to go... I would guess that this is the vast minority
however. In any case, I saw some pretty major speed improvements moving
from FCNTL to FLOCK.
Here's the patch:
---------->8 cut here-------------------------
*** Ohttp_main.c Mon Aug 7 11:57:05 1995
--- http_main.c Mon Aug 7 13:01:02 1995
***************
*** 137,143 ****
int one_process = 0;
! #ifdef FCNTL_SERIALIZED_ACCEPT
struct flock lock_it = { F_WRLCK, 0, 0, 0 };
struct flock unlock_it = { F_UNLCK, 0, 0, 0 };
--- 137,143 ----
int one_process = 0;
! #if defined(FCNTL_SERIALIZED_ACCEPT)
struct flock lock_it = { F_WRLCK, 0, 0, 0 };
struct flock unlock_it = { F_UNLCK, 0, 0, 0 };
***************
*** 159,164 ****
--- 159,186 ----
void accept_mutex_off()
{
fcntl (fileno(server_conf->error_log), F_SETLKW, &unlock_it);
+ }
+
+ #elif defined(FLOCK_SERIALIZED_ACCEPT)
+
+ void accept_mutex_on()
+ {
+ int ret;
+
+ while ((ret = flock(fileno(server_conf->error_log),LOCK_EX)) < 0
+ && errno == EINTR)
+ continue;
+
+ if (ret < 0) {
+ log_error ("Unknown failure grabbing accept lock. Exiting!",
+ server_conf);
+ exit(1);
+ }
+ }
+
+ void accept_mutex_off()
+ {
+ flock (fileno(server_conf->error_log), LOCK_UN);
}
#else
/* Default --- no serialization. Other methods *could* go here,
---------->8 cut here-------------------------
--
Jim Jagielski << jim@jaguNET.com >> | "Stwike him Centuwian, vewy woughwy!"
** jaguNET Access Services ** | - Pontius Piwate
++ Email: info@jaguNET.com +++ Voice: 410-931-3157 ++
++ http://www.jaguNET.com/ +++ Data: 931-7060 ("guest") ++
Brian
---------- Forwarded message ----------
From: Jim Jagielski <jim@shado.jaguNET.com>
Subject: Additional serialization code
To: new-httpd@hyperreal.com
Date: Mon, 7 Aug 1995 19:21:45 -0400 (EDT)
As mentioned in a previous message, although the concept of serializing
accept() is _very_ code, for some systems and setups, the use of fcntl()
to perform the lock may not be the best idea, since it's implementation
of fcntl() locking (esp. under NFS) can take an appreciable amount of
time.
I've added another possible option: FLOCK_SERIALIZED_ACCEPT. Basically,
it simply uses flock() instead of fcntl(). Now, of course, if the server
and the log file are on different machines, then flock() won't work and
fcntl() is the way to go... I would guess that this is the vast minority
however. In any case, I saw some pretty major speed improvements moving
from FCNTL to FLOCK.
Here's the patch:
---------->8 cut here-------------------------
*** Ohttp_main.c Mon Aug 7 11:57:05 1995
--- http_main.c Mon Aug 7 13:01:02 1995
***************
*** 137,143 ****
int one_process = 0;
! #ifdef FCNTL_SERIALIZED_ACCEPT
struct flock lock_it = { F_WRLCK, 0, 0, 0 };
struct flock unlock_it = { F_UNLCK, 0, 0, 0 };
--- 137,143 ----
int one_process = 0;
! #if defined(FCNTL_SERIALIZED_ACCEPT)
struct flock lock_it = { F_WRLCK, 0, 0, 0 };
struct flock unlock_it = { F_UNLCK, 0, 0, 0 };
***************
*** 159,164 ****
--- 159,186 ----
void accept_mutex_off()
{
fcntl (fileno(server_conf->error_log), F_SETLKW, &unlock_it);
+ }
+
+ #elif defined(FLOCK_SERIALIZED_ACCEPT)
+
+ void accept_mutex_on()
+ {
+ int ret;
+
+ while ((ret = flock(fileno(server_conf->error_log),LOCK_EX)) < 0
+ && errno == EINTR)
+ continue;
+
+ if (ret < 0) {
+ log_error ("Unknown failure grabbing accept lock. Exiting!",
+ server_conf);
+ exit(1);
+ }
+ }
+
+ void accept_mutex_off()
+ {
+ flock (fileno(server_conf->error_log), LOCK_UN);
}
#else
/* Default --- no serialization. Other methods *could* go here,
---------->8 cut here-------------------------
--
Jim Jagielski << jim@jaguNET.com >> | "Stwike him Centuwian, vewy woughwy!"
** jaguNET Access Services ** | - Pontius Piwate
++ Email: info@jaguNET.com +++ Voice: 410-931-3157 ++
++ http://www.jaguNET.com/ +++ Data: 931-7060 ("guest") ++