From owner-freebsd-arch@freebsd.org Thu Oct 8 21:27:31 2015 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A1A199D1B1B for ; Thu, 8 Oct 2015 21:27:31 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [199.48.133.146]) by mx1.freebsd.org (Postfix) with ESMTP id 8A11C8E6 for ; Thu, 8 Oct 2015 21:27:31 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from marvin.beer.town (unknown [76.164.8.130]) by smtp.vangyzen.net (Postfix) with ESMTPSA id E3E53564B3; Thu, 8 Oct 2015 16:27:29 -0500 (CDT) Subject: Re: RFC: Automatically Reloading /etc/resolv.conf To: freebsd-arch@freebsd.org, Warner Losh References: <5615886F.3060601@FreeBSD.org> From: Eric van Gyzen X-Enigmail-Draft-Status: N1110 Message-ID: <5616DFC0.8070404@FreeBSD.org> Date: Thu, 8 Oct 2015 16:27:28 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Oct 2015 21:27:31 -0000 On 10/08/2015 11:13, Warner Losh wrote: > > Make sure you rate limit it. Agreed. As I just wrote in my other reply, calling stat() on every query reduces queries-per-second by 15.87%. Rate-limiting to one stat() every ten seconds fixes it. That is, by manually running three or four benchmarks with and without my changes, I see no real difference. This was on amd64 where the cost of clock_gettime() is trivialized by vdso. >> Disadvantage: This would persistently allocate an open file and a >> kqueue for every thread that ever uses the resolver, for the life of the >> thread. This seems fairly expensive. >> > > Why does this follow? Can't you have a global one for the process? Well, gee, that seems like a good compromise, now that you mention it. ;-) Seriously, I simply didn't consider that. Given that the rate-limited stat() approach is so cheap, I wonder if it's worth the trouble to try the global kqueue approach. >> NetBSD uses this approach. It mitigates most of the space-cost by using >> a shared pool of res_state objects, instead of one per thread [that uses >> the resolver]. On each query, a thread allocates/borrows a res_state >> from the pool, uses it, and returns it. So, the number of objects is >> only the high water mark of the number of threads _concurrently_ issuing >> resolver queries.n >> > > What's the locking scaleability here when resolv.conf changes? The mutex is only held during one or two SLIST operations, so the locking is independent of resolv.conf changing. Maybe I misunderstood your question? >> FYI, I'm leaning toward the "stat" approach. >> > > It sounds simpler to implement, but likely a higher overhead than the > kqueue approach. resolv.conf changes on an time scale measured in minutes > or hours for the mobile user, and on the scale of years for servers. > Polling on the scale of seconds (at least two orders of magnitude faster > than the rate of change) seems like a lot of extra work over the life of > resolv.conf. On the other hand, when changes _are_ needed, you don't want to restart critical services in order to make them effective. (This is my motivation, in fact.) It would be trivial to add a "no-reload" option so performance-sensitive users can turn it off. In fact, I half expected this request from someone focused on embedded work, such as yourself. ;-) Eric