Browse Source

[core] optimize syscalls per connection

personal/stbuehler/wip
Stefan Bühler 11 years ago
parent
commit
0fcbfb7ab7
  1. 1
      configure.ac
  2. 2
      include/lighttpd/server.h
  3. 1
      src/CMakeLists.txt
  4. 1
      src/config.h.cmake
  5. 2
      src/main/connection.c
  6. 15
      src/main/server.c

1
configure.ac

@ -170,6 +170,7 @@ AC_CHECK_FUNCS([ \
sendfile64 \
sendfilev \
writev \
accept4 \
])
dnl Check for IPv6 support

2
include/lighttpd/server.h

@ -36,6 +36,8 @@ struct liServerSocket {
liServer *srv;
ev_io watcher;
liSocketAddress local_addr;
/* Custom sockets (ssl) */
gpointer data;
liConnectionWriteCB write_cb;

1
src/CMakeLists.txt

@ -76,6 +76,7 @@ CHECK_FUNCTION_EXISTS(sendfile HAVE_SENDFILE)
CHECK_FUNCTION_EXISTS(sendfile64 HAVE_SENDFILE64)
CHECK_FUNCTION_EXISTS(sendfilev HAVE_SENDFILEV)
CHECK_FUNCTION_EXISTS(writev HAVE_WRITEV)
CHECK_FUNCTION_EXISTS(accept4 HAVE_ACCEPT4)
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
#include <sys/socket.h>

1
src/config.h.cmake

@ -146,6 +146,7 @@
#cmakedefine HAVE_STRPTIME
#cmakedefine HAVE_SYSLOG
#cmakedefine HAVE_WRITEV
#cmakedefine HAVE_ACCEPT4
/* libcrypt */
#cmakedefine HAVE_LIBCRYPT

2
src/main/connection.c

@ -766,7 +766,7 @@ void li_connection_start(liConnection *con, liSocketAddress remote_addr, int s,
con->info.remote_addr = remote_addr;
li_sockaddr_to_string(remote_addr, con->info.remote_addr_str, FALSE);
con->info.local_addr = li_sockaddr_local_from_socket(s);
con->info.local_addr = li_sockaddr_dup(srv_sock->local_addr);
li_sockaddr_to_string(con->info.local_addr, con->info.local_addr_str, FALSE);
li_waitqueue_push(&con->wrk->io_timeout_queue, &con->io_timeout_elem);

15
src/main/server.c

@ -19,6 +19,7 @@ static void state_ready_cb(struct ev_loop *loop, struct ev_async *w, int revents
static liServerSocket* server_socket_new(int fd) {
liServerSocket *sock = g_slice_new0(liServerSocket);
sock->local_addr = li_sockaddr_local_from_socket(fd);
sock->refcount = 1;
sock->watcher.data = sock;
li_fd_init(fd);
@ -430,7 +431,19 @@ static void li_server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) {
}
l = sizeof(sa);
#ifdef HAVE_ACCEPT4
if (-1 == (s = accept4(w->fd, &sa.plain, &l, SOCK_NONBLOCK))) {
if (ENOSYS != errno) break;
/* fallback */
if (-1 == (s = accept(w->fd, &sa.plain, &l))) break;
li_fd_no_block(s); /* we don't fork, don't care about FD_CLOEXEC */
}
#else
if (-1 == (s = accept(w->fd, &sa.plain, &l))) break;
li_fd_no_block(s); /* we don't fork, don't care about FD_CLOEXEC */
#endif
wrk = srv->main_worker;
min_load = g_atomic_int_get(&wrk->connection_load);
@ -443,8 +456,6 @@ static void li_server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) {
remote_addr = li_sockaddr_remote_from_socket(s);
}
li_fd_no_block(s); /* we don't fork, don't care about FD_CLOEXEC */
for (i = 1; i < srv->worker_count; i++) {
liWorker *wt = g_array_index(srv->workers, liWorker*, i);
guint load = g_atomic_int_get(&wt->connection_load);

Loading…
Cancel
Save