From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 27 20:59:25 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 88ACE3DC for ; Thu, 27 Mar 2014 20:59:25 +0000 (UTC) Received: from frv199.fwdcdn.com (frv199.fwdcdn.com [212.42.77.199]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3F9B138A for ; Thu, 27 Mar 2014 20:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ukr.net; s=ffe; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Cc:To:Subject:From:Date; bh=Z3t/TDda1l16Zy5W47kZ/qEFPwl91vE7qJkFQHMgxZI=; b=NlrJLfwkjcUffNoiJ/KAMzGnOLhT5LcJPoa7uHSucUS7Zl9F5XeAh4CdGqU+OZXrMW7JfRfyUE1DAL5T1l5zpLbLvOiGYXiMTjHq5LdW4Nz7a0q1JB7j8jdEOcizGLOXl5hOdpM4qUwyG9P+kLKIalPY/OyjowhvJNx9Oh86BPY=; Received: from [10.10.10.35] (helo=frv35.fwdcdn.com) by frv199.fwdcdn.com with smtp ID 1WTHOK-000NNh-K6 for freebsd-hackers@freebsd.org; Thu, 27 Mar 2014 22:59:12 +0200 Date: Thu, 27 Mar 2014 22:59:12 +0200 From: Vladislav Prodan Subject: Re: arp(8) performance - use if_nameindex() instead of if_indextoname() To: Nick Rogers X-Mailer: mail.ukr.net 5.0 Message-Id: <1395953784.953193393.sslrpyfe@frv35.fwdcdn.com> In-Reply-To: References: MIME-Version: 1.0 Received: from universite@ukr.net by frv35.fwdcdn.com; Thu, 27 Mar 2014 22:59:12 +0200 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: binary Content-Disposition: inline Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Mar 2014 20:59:25 -0000 > I propose that instead of calling if_indextoname() for every entry, > we leverage if_nameindex() to obtain a cache of if_index to if_name > mappings, before printing all the entries. This results in a > considerable performance improvement for my situation, and also > handles the case that was "fixed" in the commit I just mentioned. > > I took a shot at this and came up with the following diff against > HEAD. I used routed's route6d.c as a reference, which is the only > thing I could find utilizing if_nameindex(). I am currently using this > in production environments with great success. > > The following illustrates the performance improvement: > > [root@vm ~/arp]# ifconfig -a | grep vlan | grep interface | wc -l > 1500 > > [root@vm ~/arp]# arp -na | wc -l > 1503 > > [root@vm ~/arp]# time /usr/sbin/arp.old -na > /dev/null > > real 0m5.529s > user 0m0.813s > sys 0m4.231s > > [root@vm ~/arp]# time /usr/sbin/arp -na > /dev/null > > real 0m0.011s > user 0m0.008s > sys 0m0.002s > [root@vm ~/arp]# > > > I realize this may not be the cleanest way of implementing > if_nameindex within arp.c. I'm hoping Max Laier or someone else can > help me out (again) and get an adequate fix committed. Thanks! > Thanks, it works. Can set separate file somewhere? And then somewhere mailing list spoiled formatting patch ... # ngctl list | grep ngeth | wc -l 12003 # ifconfig -a | egrep -e 'inet ' | wc -l 12007 # time /usr/sbin/arp.old -na > /dev/null 150.661u 551.002s 11:53.71 98.3% 20+172k 1+0io 0pf+0w # time /usr/sbin/arp -na > /dev/null 0.114u 0.090s 0:00.14 142.8% 20+170k 0+0io 0pf+0w -- Vladislav V. Prodan System & Network Administrator http://support.od.ua +380 67 4584408, +380 99 4060508 VVP88-RIPE