emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 100% CPU on TCP servers (on Windoze).


From: Kim F. Storm
Subject: Re: 100% CPU on TCP servers (on Windoze).
Date: Fri, 14 Jul 2006 00:35:50 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Juanma Barranquero <address@hidden> 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 <address@hidden> http://www.cua.dk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]