From owner-freebsd-questions@freebsd.org Thu Dec 22 15:15:09 2016 Return-Path: Delivered-To: freebsd-questions@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 C92C3C8BCD4 for ; Thu, 22 Dec 2016 15:15:09 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1FCB21C3C for ; Thu, 22 Dec 2016 15:15:07 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id uBMF2Zl5018686; Fri, 23 Dec 2016 02:02:36 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Fri, 23 Dec 2016 02:02:35 +1100 (EST) From: Ian Smith To: hhsheng@corp.netease.com cc: freebsd-questions@freebsd.org Subject: Re: question about fopen fd limit In-Reply-To: Message-ID: <20161223015110.X26979@sola.nimnet.asn.au> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Dec 2016 15:15:09 -0000 In freebsd-questions Digest, Vol 655, Issue 4, Message: 10 On Thu, 22 Dec 2016 11:53:08 +0800 ??? wrote: > hi all, > > hi~ > we are from Chinese Game Develop Corp, Netease. > and One of our product using FreeBsd as its OS platform. > This Game has Millions of players online , and Each Server may > holds 25000+ tcp connection at the same time.Thanks to BSD and kqueue > :) > > for example, it's one of our server , netstat cmd to list > connections overall... > netstat -an | grep 13396 (it's our listening port) | wc -l > 23221 > > recently we do some performance optimize and promote this connect > limit to 28000+ or 30000+. > But we find Freebsd has a limit that this huge online number will > take 28000+ fd, and bsd FILE * struct's fd only support to SHORT . > such as .. > > struct __sFILE { > ... > short _file; /* (*) fileno, if Unix descriptor, else -1 */ > ... > > so if our server want to fopen some file when we still hold this > online number, the fd amount may easily exceed 32767, and fopen > definitely return a err code. then the server will appear some fataly > ERROR. > > we do a simple test and confirm this situation. > > then in fopen's code , we notice that we can use open to return a > fd instread of fopen to avoid this overflow, as below > > 68 /* > 1 * File descriptors are a full int, but _file is only a short. > 2 * If we get a valid file descriptor that is greater than > 3 * SHRT_MAX, then the fd will get sign-extended into an > 4 * invalid file descriptor. Handle this case by failing the > 5 * open. > 6 */ > > > BUT ... so many c lib FILE series function needs a FILE * pointer > as input argument, we can't convert all of them to fd, or it will be > a rather suffering things to us. > > and even in BSD 10 , it seems this short limit still there , but > other OS as debian , FILE strucnt's fileno is a int . > > we found an unoffical patch easily change this fileno to unsigned , > but we are a very stready project, we can't afford the risk to use an > unoffical patch. > > so, do you have any plan to change this fopen fd limit to UNSIGNED > SHORT or int in the future ? ushort is enough for us . > if you do , we are really glad and excited~~~~~~~if you don't ,it > donen't matter, plz give us a reply so that we may need to > find some other plan to resolved this suffering thing. > LoL, thank you !!!!! > > yours sincerely > winson sheng If you do not get a useful response here, I recommend reposting this to freebsd-net@freebsd.org where it will much more likely catch the eye of people who work with network code. cheers, Ian