From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 19 11:03:01 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A2B2B1065670 for ; Fri, 19 Aug 2011 11:03:01 +0000 (UTC) (envelope-from aboutbus@gmail.com) Received: from mail-gy0-f182.google.com (mail-gy0-f182.google.com [209.85.160.182]) by mx1.freebsd.org (Postfix) with ESMTP id 6597E8FC08 for ; Fri, 19 Aug 2011 11:03:01 +0000 (UTC) Received: by gyd10 with SMTP id 10so2441760gyd.13 for ; Fri, 19 Aug 2011 04:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=XkMngYPZ8uyEzpPqYAZFFkBpWKusZDoFnRFbjfItezQ=; b=HNRWKabsyffoMpuSh6CdM+TQwrdQy9Ueh3wydapwD/AhTW6GyOvHjDZAsjADYo7YAs zuO+hteU+PftLEPO+i+M+syPkVPYvTpOXgv9CbaRzVlX9SK7rKNxduwHrn2vW74admwn TS2vcq7gTgxFL5b72st5lm4EPGGEIzSQtwTi0= MIME-Version: 1.0 Received: by 10.236.195.73 with SMTP id o49mr6404706yhn.23.1313750005356; Fri, 19 Aug 2011 03:33:25 -0700 (PDT) Received: by 10.236.110.9 with HTTP; Fri, 19 Aug 2011 03:33:25 -0700 (PDT) Date: Fri, 19 Aug 2011 13:33:25 +0300 Message-ID: From: about bus To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Kqueue + Libevent X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Aug 2011 11:03:01 -0000 Hello! I've got some interesting problem with my own server which use Libevent and Kqueue. Kqueue holds some sockets for a long time (while reading data) and gives it back to application when another side closes connection. I have server with FreeBSD 7.2 which serves several thousands requests per second. Nginx -> statical requests, images -> backend for dynamical requests: Libevent based http server written on C Sometimes, about 0.1% of request, Nginx displays error: "Operation timed out while reading response from upstream." Switching Libevent from Kqueue to Poll in my http server fixes the problem. Poll works fine without errors in Nginx log file. Debug output for timeouted requests from Libevent: 1) Libevent accepts incoming connection from Nginx. 2) Libevent adds socket to Kqueue for waiting incoming data with HTTP request. 3) No events on socket for 60 seconds, no received data. (60 - timeout value in Nginx config) 4) On the another side Nginx closes connection and displays timeout error. 5) At the same time Kqueue reports about incoming data and returns socket to Libevent. 6) Libevent reads correct HTTP request from socket and passes it to my handler. Why Kqueue does not reports about read event for so long time? Why Kqueue do it only when another side closes connection? It is strange, because Poll does not have such problems.