From mkotlov at gmail.com Tue Mar 17 08:49:27 2009 From: mkotlov at gmail.com (Mari Kotlov) Date: Tue Mar 17 08:49:33 2009 Subject: sysctl with KERN_BOOTTIME option vs. gettimeofday() Message-ID: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com> Hi everyone, I am doing a port of C++ code from Windows to FreeBSD and need to replace function GetTickCount(), which is used mostly for the purposes of obtaining elapsed time (e.g. as a millisecond timer). As I understand it, there are two ways to do that: 1) via sysctl() function with CTL_KERN&KERN_BOOTTIME options and 2) via gettimeofday(). In both case, struct timeval is returned, so I can compute the difference between the two times and get the elapsed time. I am wondering if anyone could tell me performance implications of using sysctl() function call to obtain system boot time vs. gettimeofday(). Is one better than the other? More efficient? Are there advantages or disadvantages to using either of these two methods? Any insight would be appreciated. Thanks very much in advance, Mari. From pieter at degoeje.nl Tue Mar 17 10:12:56 2009 From: pieter at degoeje.nl (Pieter de Goeje) Date: Tue Mar 17 10:13:02 2009 Subject: sysctl with KERN_BOOTTIME option vs. gettimeofday() In-Reply-To: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com> References: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com> Message-ID: <200903171752.37337.pieter@degoeje.nl> On Tuesday 17 March 2009 16:17:55 Mari Kotlov wrote: > Hi everyone, > I am doing a port of C++ code from Windows to FreeBSD and need to > replace function GetTickCount(), which is used mostly for the purposes > of obtaining elapsed time (e.g. as a millisecond timer). As I > understand it, there are two ways to do that: 1) via sysctl() function > with CTL_KERN&KERN_BOOTTIME options and 2) via gettimeofday(). In both > case, struct timeval is returned, so I can compute the difference > between the two times and get the elapsed time. > > I am wondering if anyone could tell me performance implications of > using sysctl() function call to obtain system boot time vs. > gettimeofday(). Is one better than the other? More efficient? Are > there advantages or disadvantages to using either of these two > methods? Any insight would be appreciated. > > Thanks very much in advance, > Mari. For the purpose of determining the elapsed time between two measurements, I can recommend clock_gettime(2) w/ CLOCK_MONOTONIC as clock_id. Sysctl is definately not meant to be used for this, as it is not portable and has probably more overhead than clock_gettime() or gettimeofday(). - Pieter From ab at addr.com Mon Mar 23 16:43:23 2009 From: ab at addr.com (Anthony Bourov) Date: Mon Mar 23 16:43:46 2009 Subject: nsdispatch performance issue for large group files (libc) Message-ID: <7E0B3E3BC5054DF2A0BC814501B08324@ABPC> Regarding performance of: lib/libc/net/nsdispatch.c When used from: lib/libc/net/getgrent.c (called by initgroups()) I don't normally post here but I wanted to get some feed back on a performance issue that I spotted. I run a large number of high-volume web hosting servers and noticed on some of the servers a severe decrease in Apache's performance when the /etc/group file is large (over 100,000 entries in a group file as it is combined across servers). I did a trace and found the following operation: stat("/etc/nsswitch.conf", {st_mode=052, st_size=4503681233059861, ...}) = 0 repeating as many times as there is groups in the group file. I narrowed the problem down to where apache calls "initgroups()" before forking each process (nothing wrong here). And init groups goes through every entry in the group file using getgrent(), which in turn calls nsdispatch and which for every single call does "stat" on "/etc/nsswitch.conf" to see if it changed. This issue impacts different servers differently, on most of the SCSI servers this delays apache startup my maybe a minute, however, on a Dell SATA raid the "stat" command was significantly slower and caused everything to come to a halt for several minuted every time apache starts. In my opinion this is a very significant performance issue when working with large servers. Most programs, including apache, will call "initgroups()" for every time they fork, and it the group file is large this means as many "stat" requests on the file system as there are entries in the group file for every single fork() that the server does. For myself I just made it never test "stat" on "/etc/nsswitch.conf" after the first time since I know that file is never modified. However, a better solution would be to somehow let nsdispatch know that it is being ran in batch mode and should not keep testing if the file has changed. This would effect both "getgrent" and "getpwent". From ivoras at freebsd.org Sun Mar 29 11:05:02 2009 From: ivoras at freebsd.org (Ivan Voras) Date: Sun Mar 29 11:05:15 2009 Subject: nsdispatch performance issue for large group files (libc) In-Reply-To: <7E0B3E3BC5054DF2A0BC814501B08324@ABPC> References: <7E0B3E3BC5054DF2A0BC814501B08324@ABPC> Message-ID: Anthony Bourov wrote: > Regarding performance of: lib/libc/net/nsdispatch.c Have you tried nscd(8)? It should at least amortize the startup costs... (see nsswitch.conf(5) for instructions how to set it up) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 258 bytes Desc: OpenPGP digital signature Url : http://lists.freebsd.org/pipermail/freebsd-performance/attachments/20090329/edd9a50a/signature.pgp