From owner-freebsd-ports@freebsd.org Sun Apr 14 04:59:59 2019 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 112021559C71 for ; Sun, 14 Apr 2019 04:59:59 +0000 (UTC) (envelope-from koobs.freebsd@gmail.com) Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 71244819A2 for ; Sun, 14 Apr 2019 04:59:57 +0000 (UTC) (envelope-from koobs.freebsd@gmail.com) Received: by mail-pl1-x644.google.com with SMTP id t16so7000589plo.0 for ; Sat, 13 Apr 2019 21:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:reply-to:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=XpC+aFoM0llEKpdWpisceZKQk4BvlhTI97dRWMB6VZI=; b=oWg+PS9XB8B6BsDD8qRa/B/hklqDuFPC6mIZI5mglTv1+h4+jnccuIAkJlJDqhlDWE qzgDiSEAENTklEyjsiZ02rCFTTcE8hS3tBxmQE93GW/ADPKqoA9ZDV4Mn+cs4w4DyqYu 7L//c2ImjT+TMBJb18S7AfLSNB0TO94vU0KVKErjBPIaB+Vx92IGTrNR/22eI1y1LrRc K6YUWNDvUzS0HX//JIPwlp17DwkzU0hz91POIT8beCooTjs2E845dw5s6EjezRjUuJmx 3T5UyOLTNFFGhYfdcvKr/2Kpgf/oMmAekBO6gQgcdrP5NCkrOEpKrr/ByCwkf8j4uTM7 MYOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=XpC+aFoM0llEKpdWpisceZKQk4BvlhTI97dRWMB6VZI=; b=fJb1OlP7ZuPTNXse5Jothmx9gk22NHO6VZlP3sCNuLTe7nE36EWiUCVpEZivpBb/Fu s3Zquc5U5OzCF1MFNF6P3SGOxGtyH95SFAYUroYinMjBTq0OhZWNvZS+ed905c7T6hKM bnBf5AEEmIsOPnldR0neBw98LCN//5ID/c2QhiNLaoQqdvGaftXCAb5KKd6j5bbBNmUD a3ZNRMiC3PPUOF0zRgri3LsxEoe3I0WD4JrMCfGMWkVDOUHoGT8RsAQdhai2bekyzPiN ICTd+n/TNrxxNO3FA/moitGMObkSZrVuOXPlKANKURRdSOEJxQ3Sd4JzNMecdCbllcEH kETQ== X-Gm-Message-State: APjAAAUOyOFNfgMNjymmeHbe0YEqAbDhjxXt4Hhx40uBOQStc9w+kM3/ b5vQLg09kKMiUAT1zS7nMzc5znKH X-Google-Smtp-Source: APXvYqxB6Fm0Rf2sVNX1Celeh7URrwD07Ij19lV+1DrUFZFrKU11ywkDDl+3nNB6tWKyqv5FiHjC/g== X-Received: by 2002:a17:902:bb84:: with SMTP id m4mr28316000pls.302.1555217996308; Sat, 13 Apr 2019 21:59:56 -0700 (PDT) Received: from ?IPv6:2403:5800:7100:5d01:856e:96f0:533c:85d4? (2403-5800-7100-5d01-856e-96f0-533c-85d4.ip6.aussiebb.net. [2403:5800:7100:5d01:856e:96f0:533c:85d4]) by smtp.gmail.com with ESMTPSA id o81sm60192300pfa.156.2019.04.13.21.59.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Apr 2019 21:59:55 -0700 (PDT) Sender: Kubilay Kocak Reply-To: koobs@FreeBSD.org Subject: Re: python 3 subprocess performance To: Dima Pasechnik , Alexander Zagrebin Cc: FreeBSD Ports References: <20190411161649.1b740d21@vm2.home.zagrebin.ru> <8f3f8413-60f2-bb03-a6b4-4f6364cdc3df@rlwinm.de> <20190411143926.5rg4jskmodt4shhi@laparbeit> <9729db47-12c4-caf4-cdcf-1913dab73c8e@rlwinm.de> <20190412101012.4142854f@vm2.home.zagrebin.ru> <20190412104531.7b492a3c@vm2.home.zagrebin.ru> From: Kubilay Kocak Message-ID: <800de545-0310-fcda-ebae-a4dffabe47e9@FreeBSD.org> Date: Sun, 14 Apr 2019 14:59:53 +1000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Thunderbird/67.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 71244819A2 X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=oWg+PS9X; spf=pass (mx1.freebsd.org: domain of koobsfreebsd@gmail.com designates 2607:f8b0:4864:20::644 as permitted sender) smtp.mailfrom=koobsfreebsd@gmail.com X-Spamd-Result: default: False [-3.87 / 15.00]; HAS_REPLYTO(0.00)[koobs@FreeBSD.org]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.93)[-0.933,0]; FORGED_SENDER(0.30)[koobs@FreeBSD.org,koobsfreebsd@gmail.com]; FREEMAIL_TO(0.00)[gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_NEQ_ENVFROM(0.00)[koobs@FreeBSD.org,koobsfreebsd@gmail.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; TAGGED_RCPT(0.00)[freebsd]; PREVIOUSLY_DELIVERED(0.00)[freebsd-ports@freebsd.org]; DMARC_NA(0.00)[FreeBSD.org]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[4.4.6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; IP_SCORE(-0.73)[ip: (1.58), ipnet: 2607:f8b0::/32(-2.95), asn: 15169(-2.19), country: US(-0.06)] X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Apr 2019 04:59:59 -0000 On 12/04/2019 8:41 pm, Dima Pasechnik wrote: > On Fri, Apr 12, 2019 at 9:46 AM Alexander Zagrebin wrote: >> >> В Fri, 12 Apr 2019 09:36:13 +0200 >> Dima Pasechnik пишет: >> >>> On Fri, Apr 12, 2019 at 9:11 AM Alexander Zagrebin >>> wrote: >>>> >>>> В Thu, 11 Apr 2019 17:32:42 +0200 >>>> Jan Bramkamp пишет: >>>> >>>>> The reason is that that python does something stupid (tm). It >>>>> tries to close all file descriptors (except a few whitelisted >>>>> ones) up to the maximum file descriptor number. It does this by >>>>> asking the kernel for the maximum possible number and closing >>>>> everything it doesn't want to keep. Some time later someone came >>>>> up with an optimization (read the open file descriptors >>>>> from /dev/fd). All of this pain and suffering is caused by good >>>>> old Ulrich Drepper braindamage: >>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=10353. >>>>> >>>>> Most Linux distros have lower default file descriptor limits than >>>>> FreeBSD making this workaround less painful. The correct solution >>>>> would be to teach python3 about closefrom(2). >>>> >>>> Thank you for hint and testing! >>>> >>>> Indeed the problem is in closing more than 400,000 file descriptors >>>> in loop. It seems that all current versions of Python are affected. >>>> Python2 uses False as default value for the close_fds parameter of >>>> the Popen constructor, so this issue is mostly not visible. >>>> Python3 has changed this default to True. >>>> >>>> As Jan Bramkamp suggested, I've wrote simple patch to fix an issue >>>> (see attached file). It seems the problem has gone. >>> >>> The attachment has been stripped out. Could you paste the diff into >>> the message? >> >> Yes, sure. >> >> --- Modules/_posixsubprocess.c.orig 2018-12-24 00:37:14.000000000 >> +0300 +++ Modules/_posixsubprocess.c 2019-04-12 >> 09:25:21.549389000 +0300 @@ -235,11 +235,15 @@ >> _close_fds_by_brute_force(long start_fd, } >> start_fd = keep_fd + 1; >> } >> +#if defined(__FreeBSD__) >> + closefrom(start_fd); >> +#else >> if (start_fd <= end_fd) { >> for (fd_num = start_fd; fd_num < end_fd; ++fd_num) { >> close(fd_num); >> } >> } >> +#endif >> } >> >>> If this is a Python issue, shouldn't this be reported upstream, on >>> https://bugs.python.org ? >> >> May be. Rather, it is a FreeBSD-specific optimization. > > Well, closefrom() is also available in Darwin (a.k.a. MacOSX :-)), > OpenBSD and NetBSD. (It's not documented in current MacOSX, but it is > there, I just checked) > Anyway, FreeBSD Python maintainers will ask for an upstream PR. > > I can do such a PR is noone else is willing to... > > Dima > > Hi Dima, Issue exists for this: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221700 Pending *upstreamable* patches for lang/python*, that we can carry locally until released.