Welcome! Log In Create A New Profile

Advanced

Dead code in accept

Serguei I. Ivantsov
August 04, 2013 05:16PM
Hi,

While researching nginx, I found that there are a lot of dead code, mostly
in ngx_event_accept.c
One of those blocks:

if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
ev->available = 1;

} else if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) {
ev->available = ecf->multi_accept;
}

I have EPOLL and do not have neither RTSIG nor KQUEUE on my Linux, but
this conditionals are executed on every accept. This wastes CPU cycles and
cause possible branch miss-predictions.

I see two ways, how to address this.

1. nginx-style - wrap this code blocks with pre-processor #if/#endif the
same way it is done in other parts of nginx code. Resulting code will look
like this:

#if (NGX_HAVE_RTSIG)
if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
ev->available = 1;
} else
#endif
#if (NGX_HAVE_KQUEUE)
if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) {
#endif
ev->available = ecf->multi_accept;
#if (NGX_HAVE_KQUEUE)
}
#endif

Yep, some kind of spaghetti.

2. A little "hack".
In ngx_event.h we can conditionally define NGX_USE_*_EVENT constants to
zero, if we have no support for specific event module.
Thus, we do not need to touch the code, and optimizing compiler will
remove this code blocks, because condition expression is constant and
available at compile time.

A little test with high volume of simple requests shows 0.5% overall speed
improvement.

I have patches for both, so just need to know which approach is better in
terms of nginx ideology.

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Dead code in accept

Serguei I. Ivantsov 997 August 04, 2013 05:16PM

Re: Dead code in accept

Maxim Dounin 462 August 04, 2013 06:20PM

Re: Dead code in accept

Tom van der Woerdt 463 August 05, 2013 03:16AM

Re: Dead code in accept

splitice 784 August 05, 2013 05:06AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 257
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready