all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: Emacs Devel <emacs-devel@gnu.org>
Subject: Re: 100% CPU on TCP servers  (on Windoze).
Date: Fri, 14 Jul 2006 00:35:50 +0200	[thread overview]
Message-ID: <m3zmfduo8p.fsf_-_@kfs-l.imdomain.dk> (raw)
In-Reply-To: <f7ccd24b05081808516481551@mail.gmail.com> (Juanma Barranquero's message of "Thu, 18 Aug 2005 17:51:41 +0200")

Juanma Barranquero <lekktu@gmail.com> 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 <storm@cua.dk> http://www.cua.dk

  parent reply	other threads:[~2006-07-13 22:35 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-06 18:38 100% CPU on TCP servers Juanma Barranquero
2005-08-18 15:51 ` Juanma Barranquero
2005-09-09 12:53   ` Kim F. Storm
2005-09-09 15:25     ` Juanma Barranquero
2005-09-10  7:47   ` Jason Rumney
2005-09-10 23:01     ` Kim F. Storm
2005-10-12 15:07     ` Kim F. Storm
2005-10-12 22:42       ` Juanma Barranquero
2006-07-13 22:35   ` Kim F. Storm [this message]
2006-07-14  8:15     ` 100% CPU on TCP servers (on Windoze) Jason Rumney
2006-07-14  9:54       ` Kim F. Storm
2006-07-14 10:54         ` Juanma Barranquero
2006-07-14  9:51     ` Jason Rumney
2006-07-14 10:23       ` Kim F. Storm
2006-07-14 10:43         ` Jason Rumney
2006-07-14 11:14           ` Eli Zaretskii
2006-07-14 10:50         ` Juanma Barranquero
2006-07-14 11:16           ` Kim F. Storm
2006-07-14 11:42             ` Kim F. Storm
2006-07-14 12:27               ` Juanma Barranquero
2006-07-14 13:08                 ` Eli Zaretskii
2006-07-14 13:59                   ` Jason Rumney
2006-07-14 14:22                     ` Kim F. Storm
2006-07-14 14:41                       ` Jason Rumney
2006-07-14 17:29                       ` Eli Zaretskii
2006-07-14 18:12                         ` Stefan Monnier
2006-07-14 15:43                     ` Stuart D. Herring
2006-07-14 13:24                 ` Kim F. Storm
2006-07-14 13:40                   ` Eli Zaretskii
2006-07-14 14:04                     ` Kim F. Storm
2006-07-14 15:28                   ` Juanma Barranquero
2006-07-14 22:07                     ` Kim F. Storm
2006-07-14 23:23                       ` Juanma Barranquero
2006-07-15  0:50                         ` Kim F. Storm
2006-07-15  2:09                           ` Juanma Barranquero
2006-07-15  9:05                           ` Eli Zaretskii
2006-07-15 13:54                             ` Juanma Barranquero
2006-07-15 14:59                               ` Stefan Monnier
2006-07-15 15:30                                 ` Juanma Barranquero
2006-07-15 20:38                                   ` Eli Zaretskii
2006-07-15 22:07                                     ` Stefan Monnier
2006-07-15 17:16                             ` Richard Stallman
2006-07-15  2:04                         ` Stefan Monnier
2006-07-15  2:11                           ` Juanma Barranquero
2006-07-15 11:52                             ` Stefan Monnier
2006-07-15 13:50                               ` Juanma Barranquero
2006-07-15 14:58                                 ` Stefan Monnier
2006-07-15 15:24                                   ` Juanma Barranquero
2006-07-15 22:02                                     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3zmfduo8p.fsf_-_@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.