[PATCH] Use clock_gettime(REAL_FAST) on DragonFlyBSD

Sepherosa Ziehau sepherosa at gmail.com
Thu Jun 2 12:48:19 UTC 2016


Hi,

On DragonflyBSD only clock_gettime(*_FAST) avoids system call and time
counter read cost (kinda like Linux VDSO).  This gives some
improvement for performance and reduces latency.

My testing setup consists two clients and one nginx (recent head code)
server, two clients connected to the nginx server through two 10Ge
(82599).  15K concurrent connections from each client; client runs a
modified version of wrk and each connection only carries one request
for an 1KB file.

Performance goes from 183Kreqs/s to 184Kreqs/s (admittedly pretty
minor).  Average latency reduces 2ms (98ms -> 96ms).  Latency stdev
reduces 6ms (198ms -> 192ms).

Patch is attached.

Thanks,
sephe

-- 
Tomorrow Will Never Die
-------------- next part --------------
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index c128c9a..da33a64 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -58,7 +58,22 @@ void ngx_localtime(time_t s, ngx_tm_t *tm);
 void ngx_libc_localtime(time_t s, struct tm *tm);
 void ngx_libc_gmtime(time_t s, struct tm *tm);
 
+#ifdef __DragonFly__
+static inline int
+ngx_gettimeofday(struct timeval *tp)
+{
+	struct timespec ts;
+	int ret;
+
+	ret = clock_gettime(CLOCK_REALTIME_FAST, &ts);
+	tp->tv_sec = ts.tv_sec;
+	tp->tv_usec = ts.tv_nsec / 1000;
+	return ret;
+}
+#else
 #define ngx_gettimeofday(tp)  (void) gettimeofday(tp, NULL);
+#endif
+
 #define ngx_msleep(ms)        (void) usleep(ms * 1000)
 #define ngx_sleep(s)          (void) sleep(s)
 


More information about the nginx-devel mailing list