From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zheng Li Subject: [PATCH v3 9/9] oxenstored: reduce syslog call overhead Date: Thu, 25 Sep 2014 18:35:02 +0100 Message-ID: <1411666502-23709-10-git-send-email-dev@zheng.li> References: <1411666502-23709-1-git-send-email-dev@zheng.li> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XXCxA-0007En-1g for xen-devel@lists.xenproject.org; Thu, 25 Sep 2014 17:35:40 +0000 In-Reply-To: <1411666502-23709-1-git-send-email-dev@zheng.li> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Dave Scott , Joe Jin , "Luis R. Rodriguez" , Luonengjun , Zheng Li , Fanhenglong , Ian Jackson , "Liuqiming (John)" List-Id: xen-devel@lists.xenproject.org We noticed that, if configured to use syslog as the logging backend, every single line of access logging (via the syslog C binding) will call stat on /etc/localtime for 3 times. The rational behind this is probably to detect any timezone changes over time. This is a considerable cost we'd like to avoid, given the intensiveness of our access logging --- we log almost every xenstore status change (for good reason). Also a running Xen host is rarely a mobile environment, so the little benefit can hardly justify the cost. Setting up the TZ environment varialbe can avoid stat calls. Signed-off-by: Zheng Li --- tools/ocaml/xenstored/logging.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/ocaml/xenstored/logging.ml b/tools/ocaml/xenstored/logging.ml index 3d4a329..665b922 100644 --- a/tools/ocaml/xenstored/logging.ml +++ b/tools/ocaml/xenstored/logging.ml @@ -130,8 +130,17 @@ let string_of_date () = tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec (int_of_float (1000.0 *. msec)) +(* We can defer to syslog for log management *) let make_syslog_logger facility = - (* We defer to syslog for log management *) + (* When TZ is unset in the environment, each syslog call will stat the + /etc/localtime file at least three times during the process. We'd like to + avoid this cost given that we are not a mobile environment and we log + almost every xenstore entry update/watch. *) + let () = + let tz_is_set = + try String.length (Unix.getenv "TZ") > 0 + with Not_found -> false in + if not tz_is_set then Unix.putenv "TZ" "/etc/localtime" in let nothing () = () in let write ?level s = let level = match level with -- 2.1.1