From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: 100% CPU on TCP servers (on Windoze). Date: Fri, 14 Jul 2006 00:35:50 +0200 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1152830280 15188 80.91.229.2 (13 Jul 2006 22:38:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 13 Jul 2006 22:38:00 +0000 (UTC) Cc: Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 14 00:37:57 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G19oh-0003CD-2C for ged-emacs-devel@m.gmane.org; Fri, 14 Jul 2006 00:37:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G19og-0006W4-G9 for ged-emacs-devel@m.gmane.org; Thu, 13 Jul 2006 18:37:54 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G19oW-0006Vp-4I for emacs-devel@gnu.org; Thu, 13 Jul 2006 18:37:44 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G19oU-0006Vd-G4 for emacs-devel@gnu.org; Thu, 13 Jul 2006 18:37:42 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G19oU-0006Va-Az for emacs-devel@gnu.org; Thu, 13 Jul 2006 18:37:42 -0400 Original-Received: from [195.41.46.237] (helo=pfepc.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.52) id 1G19qL-0001Dm-AB for emacs-devel@gnu.org; Thu, 13 Jul 2006 18:39:37 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (0x503e2644.bynxx3.adsl-dhcp.tele.dk [80.62.38.68]) by pfepc.post.tele.dk (Postfix) with SMTP id 953CF8A0039; Fri, 14 Jul 2006 00:37:36 +0200 (CEST) Original-To: Juanma Barranquero In-Reply-To: (Juanma Barranquero's message of "Thu, 18 Aug 2005 17:51:41 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:56984 Archived-At: Juanma Barranquero writes: > (A question for process-savvy people) > > It seems like > >> (make-network-process :name "test" :server t :service t) > > on Windows makes the server process to call server_accept_connection() > continuously (in a 2.8 GHz Pentium IV I've measured around 10,200 > calls in 3,5 s, almost 2,900 calls per second). It's no wonder Emacs > is munching 50% CPU. > > Any idea why that can be happening? I took a look at this issue, and it seems quite trivial to fix. Would someone try to apply the following patch and tell me whether it makes a difference (pls. try the above example before and after applying the patch). If it doesn't compile, pls try to fix it!! I don't quite understand the pfn_ stuff in w32.c -- maybe the WSAEventSelect function need to be loaded in the same way to be available. Someone who knows this stuff, please DTRT. Of course, it would be great if you could actually try to connect to the server socket to see if it can really accept the connection and do something useful with it. *** w32.h 06 Feb 2006 18:21:50 +0100 1.19 --- w32.h 14 Jul 2006 00:09:55 +0200 *************** *** 93,98 **** --- 93,99 ---- /* fd_info flag definitions */ #define FILE_READ 0x0001 #define FILE_WRITE 0x0002 + #define FILE_LISTEN 0x0004 #define FILE_BINARY 0x0010 #define FILE_LAST_CR 0x0020 #define FILE_AT_EOF 0x0040 *** w32.c 20 May 2006 22:52:11 +0200 1.102 --- w32.c 14 Jul 2006 00:25:21 +0200 *************** *** 3295,3300 **** --- 3295,3305 ---- int rc = pfn_listen (SOCK_HANDLE (s), backlog); if (rc == SOCKET_ERROR) set_errno (); + else + { + fd_info[s].flags |= FILE_LISTEN; + WSAEventSelect (SOCK_HANDLE (s), fd_info[s].cp->char_avail, FD_ACCEPT); + } return rc; } h_errno = ENOTSOCK; *************** *** 3332,3342 **** } check_errno (); ! if (fd_info[s].flags & FILE_SOCKET) { SOCKET t = pfn_accept (SOCK_HANDLE (s), addr, addrlen); if (t != INVALID_SOCKET) ! return socket_to_fd (t); set_errno (); return -1; --- 3337,3352 ---- } check_errno (); ! if (fd_info[s].flags & FILE_LISTEN) { SOCKET t = pfn_accept (SOCK_HANDLE (s), addr, addrlen); if (t != INVALID_SOCKET) ! { ! int fd = socket_to_fd (t); ! if (fd >= 0) ! WSAEventSelect (SOCK_HANDLE (fd), fd_info[fd].cp->char_avail, FD_READ | FD_CLOSE); ! return fd; ! } set_errno (); return -1; -- Kim F. Storm http://www.cua.dk