public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: zhou drangon <drangon.mail@gmail.com>
Cc: linux-kernel@vger.kernel.org, Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Subject: Re: [take22 0/4] kevent: Generic event handling mechanism.
Date: Thu, 02 Nov 2006 08:46:41 +0100	[thread overview]
Message-ID: <4549A261.9010007@cosmosbay.com> (raw)
In-Reply-To: <aaf959cb0611011830j1ca3e469tc4a6af3a2a010fa@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3059 bytes --]

zhou drangon a écrit :
> performance is great, and we are exciting at the result.
> 
> I want to know why there can be so much improvement, can we improve 
> epoll too ?

Why did you remove most of CC addresses but lkml ?
Dont do that please...

Good question :)

Hum, I think I can look into epoll and see how it can be improved (if necessary)

This is not to say we dont need kevent ! Please Evgeniy continue your work !

Just to remind you that according to 
http://www.xmailserver.org/linux-patches/nio-improve.html David Libenzi had to 
wait 18 months before epoll being officialy added into kernel.

At that time, many applications were using epoll, and we were patching our 
kernels for that.


I cooked a very simple program (attached in this mail), using pipes and epoll, 
and got 250.000 events received per second on an otherwise lightly loaded 
machine (dual opteron 246 , 2GHz, 1MB cache per cpu) with 10.000 pipes (20.000 
handles)

It could be nice to add support for other event providers in this program 
(AF_INET & AF_UNIX sockets for example), and also add support for kevent, so 
that we really can compare epoll/kevent without a complex setup.
I should extend the program to also add/remove sources during lifetime, not 
only insert at setup time.

# gcc -O2 -o epoll_pipe_bench epoll_pipe_bench.c -lpthread
# ulimit -n 1000000
# epoll_pipe_bench -n 10000
^C after a while...

oprofile results say that ep_poll_callback() and sys_epoll_wait() use 20% of 
cpu time.
Even if we gain a two factor in cpu time or cache usage, we wont eliminate 
other costs...

oprofile results gave :

Counted CPU_CLK_UNHALTED events (Cycles outside of halt state) with a unit 
mask of 0x00 (No unit mask) count 50000
samples  %        symbol name
2015420  11.1309  ep_poll_callback
1867431  10.3136  pipe_writev
1791872   9.8963  sys_epoll_wait
1357297   7.4962  fget_light
1277515   7.0556  pipe_readv
998447    5.5143  current_fs_time
801597    4.4271  __mark_inode_dirty
755268    4.1713  __wake_up
587065    3.2423  __write_lock_failed
582931    3.2195  system_call
297132    1.6410  iov_fault_in_pages_read
296136    1.6355  sys_write
290106    1.6022  __wake_up_common
270692    1.4950  bad_pipe_w
261516    1.4443  do_pipe
257208    1.4205  tg3_start_xmit_dma_bug
254917    1.4079  pipe_poll
252925    1.3969  copy_user_generic_c
234212    1.2935  generic_pipe_buf_map
228659    1.2629  ret_from_sys_call
212541    1.1738  sysret_check
166529    0.9197  sys_read
160038    0.8839  vfs_write
151091    0.8345  pipe_ioctl
136301    0.7528  file_update_time
107173    0.5919  tg3_poll
77846     0.4299  ipt_do_table
75081     0.4147  schedule
73059     0.4035  vfs_read
69787     0.3854  get_task_comm
63923     0.3530  memcpy
60019     0.3315  touch_atime
57490     0.3175  eventpoll_release_file
56152     0.3101  tg3_write_flush_reg32
54468     0.3008  rw_verify_area
47833     0.2642  generic_pipe_buf_unmap
47777     0.2639  __switch_to
44106     0.2436  bad_pipe_r
41824     0.2310  proc_nr_files
41319     0.2282  pipe_iov_copy_from_user


Eric


[-- Attachment #2: epoll_pipe_bench.c --]
[-- Type: text/plain, Size: 2424 bytes --]

/*
 * How to stress epoll
 *
 * This program uses many pipes and two threads.
 * First we open as many pipes we can. (see ulimit -n)
 * Then we create a worker thread.
 * The worker thread will send bytes to random pipes.
 * The main thread uses epoll to collect ready pipes and read them.
 * Each second, a number of collected bytes is printed on stderr
 *
 * Usage : epoll_bench [-n X]
 */
#include <pthread.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/epoll.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>

int nbpipes = 1024;

struct pipefd {
	int fd[2];
} *tab;

int epoll_fd;

static int alloc_pipes()
{
	int i;

	epoll_fd = epoll_create(nbpipes);
	if (epoll_fd == -1) {
		perror("epoll_create");
		return -1;
	}
	tab = malloc(sizeof(struct pipefd) * nbpipes);
	if (tab ==NULL) {
		perror("malloc");
		return -1;
	}
	for (i = 0 ; i < nbpipes ; i++) {
			struct epoll_event ev;
		if (pipe(tab[i].fd) == -1)
			break;
		ev.events = EPOLLIN | EPOLLOUT | EPOLLHUP | EPOLLPRI | EPOLLET;
		ev.data.u64 = (uint64_t)i;
		epoll_ctl(epoll_fd, EPOLL_CTL_ADD, tab[i].fd[0], &ev);
	}
	nbpipes = i;
	printf("%d pipes setup\n", nbpipes);
	return 0;
}


unsigned long nbhandled;
static void timer_func()
{
	char buffer[32];
	size_t len;
	static unsigned long old;
	unsigned long delta = nbhandled - old;
	old = nbhandled;
	len = sprintf(buffer, "%lu\n", delta);
	write(2, buffer, len);
}

static void timer_setup()
{
	struct itimerval it;
	struct sigaction sg;

	memset(&sg, 0, sizeof(sg));
	sg.sa_handler = timer_func;
	sigaction(SIGALRM, &sg, 0);
	it.it_interval.tv_sec = 1;
	it.it_interval.tv_usec = 0;
	it.it_value.tv_sec = 1;
	it.it_value.tv_usec = 0;
	if (setitimer(ITIMER_REAL, &it, 0))
		perror("setitimer");
}

static void * worker_thread_func(void *arg)
{
	int fd;
	char c = 1;
	for (;;) {
		fd = rand() % nbpipes;
		write(tab[fd].fd[1], &c, 1);
	}
}


int main(int argc, char *argv[])
{
	char buff[1024];
	pthread_t tid;
	int c;

	while ((c = getopt(argc, argv, "n:")) != EOF) {
		if (c == 'n') nbpipes = atoi(optarg);
	}
	alloc_pipes();
	pthread_create(&tid, NULL, worker_thread_func, (void *)0);
	timer_setup();

	for (;;) {
		struct epoll_event events[128];
		int nb = epoll_wait(epoll_fd, events, 128, 10000);
		int i, fd;
		for (i = 0 ; i < nb ; i++) {
			fd = tab[events[i].data.u64].fd[0];
			if (read(fd, buff, 1024) > 0)
				nbhandled++;
		}
	}
}

  reply	other threads:[~2006-11-02  7:46 UTC|newest]

Thread overview: 221+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1154985aa0591036@2ka.mipt.ru>
2006-10-27 16:10 ` [take21 0/4] kevent: Generic event handling mechanism Evgeniy Polyakov
2006-10-27 16:10   ` [take21 1/4] kevent: Core files Evgeniy Polyakov
2006-10-27 16:10     ` [take21 2/4] kevent: poll/select() notifications Evgeniy Polyakov
2006-10-27 16:10       ` [take21 3/4] kevent: Socket notifications Evgeniy Polyakov
2006-10-27 16:10         ` [take21 4/4] kevent: Timer notifications Evgeniy Polyakov
2006-10-28 10:04       ` [take21 2/4] kevent: poll/select() notifications Eric Dumazet
2006-10-28 10:08         ` Evgeniy Polyakov
2006-10-28 10:28     ` [take21 1/4] kevent: Core files Eric Dumazet
2006-10-28 10:53       ` Evgeniy Polyakov
2006-10-28 12:36         ` Eric Dumazet
2006-10-28 13:03           ` Evgeniy Polyakov
2006-10-28 13:23             ` Eric Dumazet
2006-10-28 13:28               ` Evgeniy Polyakov
2006-10-28 13:34                 ` Eric Dumazet
2006-10-28 13:47                   ` Evgeniy Polyakov
2006-10-27 16:42   ` [take21 0/4] kevent: Generic event handling mechanism Evgeniy Polyakov
2006-11-07 11:26   ` Jeff Garzik
2006-11-07 11:46     ` Jeff Garzik
2006-11-07 11:58       ` Evgeniy Polyakov
2006-11-07 11:51     ` Evgeniy Polyakov
2006-11-07 12:17       ` Jeff Garzik
2006-11-07 12:29         ` Evgeniy Polyakov
2006-11-07 12:32       ` Jeff Garzik
2006-11-07 19:34         ` Andrew Morton
2006-11-07 20:52           ` David Miller
2006-11-07 21:38             ` Andrew Morton
2006-11-01 11:36 ` [take22 " Evgeniy Polyakov
2006-11-01 11:36   ` [take22 1/4] kevent: Core files Evgeniy Polyakov
2006-11-01 11:36     ` [take22 2/4] kevent: poll/select() notifications Evgeniy Polyakov
2006-11-01 11:36       ` [take22 3/4] kevent: Socket notifications Evgeniy Polyakov
2006-11-01 11:36         ` [take22 4/4] kevent: Timer notifications Evgeniy Polyakov
2006-11-01 13:06   ` [take22 0/4] kevent: Generic event handling mechanism Pavel Machek
2006-11-01 13:25     ` Evgeniy Polyakov
2006-11-01 16:05       ` Pavel Machek
2006-11-01 16:24         ` Evgeniy Polyakov
2006-11-01 18:13           ` Oleg Verych
2006-11-01 18:57             ` Evgeniy Polyakov
2006-11-02  2:12               ` Nate Diller
     [not found]                 ` <aaf959cb0611011829k36deda6ahe61bcb9bf8e612e1@mail.gmail.com>
2006-11-02  2:30                   ` zhou drangon
2006-11-02  7:46                     ` Eric Dumazet [this message]
2006-11-02  8:01                       ` Evgeniy Polyakov
2006-11-02  8:18                         ` Eric Dumazet
2006-11-02  8:46                           ` Evgeniy Polyakov
2006-11-02 11:33                             ` Eric Dumazet
2006-11-06 21:17                         ` Eric Dumazet
2006-11-07  8:32                           ` Evgeniy Polyakov
2006-11-07  9:18                           ` Evgeniy Polyakov
2006-11-07 12:09                             ` Evgeniy Polyakov
2006-11-09  7:48                               ` Evgeniy Polyakov
2006-11-03  2:42                       ` zhou drangon
2006-11-03  9:16                         ` Evgeniy Polyakov
2006-11-02  6:21                 ` Evgeniy Polyakov
2006-11-02 19:40                   ` Nate Diller
2006-11-03  8:42                     ` Evgeniy Polyakov
2006-11-03  8:57                       ` Pavel Machek
2006-11-03  9:04                         ` David Miller
2006-11-07 12:05                           ` Jeff Garzik
2006-11-03  9:13                         ` Evgeniy Polyakov
2006-11-05 11:19                           ` Pavel Machek
2006-11-05 11:43                             ` Evgeniy Polyakov
2006-11-07 12:02                 ` Jeff Garzik
2006-11-03 18:49               ` Oleg Verych
2006-11-04 10:24                 ` Evgeniy Polyakov
2006-11-04 17:47                 ` Evgeniy Polyakov
2006-11-01 16:07     ` James Morris
2006-11-07 16:50 ` [take23 0/5] " Evgeniy Polyakov
2006-11-07 16:50   ` [take23 1/5] kevent: Description Evgeniy Polyakov
2006-11-07 16:50     ` [take23 2/5] kevent: Core files Evgeniy Polyakov
2006-11-07 16:50       ` [take23 3/5] kevent: poll/select() notifications Evgeniy Polyakov
2006-11-07 16:50         ` [take23 4/5] kevent: Socket notifications Evgeniy Polyakov
2006-11-07 16:50           ` [take23 5/5] kevent: Timer notifications Evgeniy Polyakov
2006-11-07 22:53         ` [take23 3/5] kevent: poll/select() notifications Davide Libenzi
2006-11-08  8:45           ` Evgeniy Polyakov
2006-11-08 17:03             ` Evgeniy Polyakov
2006-11-07 22:16       ` [take23 2/5] kevent: Core files Andrew Morton
2006-11-08  8:24         ` Evgeniy Polyakov
2006-11-07 22:16     ` [take23 1/5] kevent: Description Andrew Morton
2006-11-08  8:23       ` Evgeniy Polyakov
2006-11-07 22:17   ` [take23 0/5] kevent: Generic event handling mechanism Andrew Morton
2006-11-08  8:21     ` Evgeniy Polyakov
2006-11-08 14:51       ` Eric Dumazet
2006-11-08 22:03         ` Andrew Morton
2006-11-08 22:44           ` Davide Libenzi
2006-11-08 23:07             ` Eric Dumazet
2006-11-08 23:56               ` Davide Libenzi
2006-11-09  7:24                 ` Eric Dumazet
2006-11-09  7:52                   ` Eric Dumazet
2006-11-09 17:12                     ` Davide Libenzi
2006-11-09  8:23 ` [take24 0/6] " Evgeniy Polyakov
2006-11-09  8:23   ` [take24 1/6] kevent: Description Evgeniy Polyakov
2006-11-09  8:23     ` [take24 2/6] kevent: Core files Evgeniy Polyakov
2006-11-09  8:23       ` [take24 3/6] kevent: poll/select() notifications Evgeniy Polyakov
2006-11-09  8:23         ` [take24 4/6] kevent: Socket notifications Evgeniy Polyakov
2006-11-09  8:23           ` [take24 5/6] kevent: Timer notifications Evgeniy Polyakov
2006-11-09  8:23             ` [take24 6/6] kevent: Pipe notifications Evgeniy Polyakov
2006-11-09  9:08         ` [take24 3/6] kevent: poll/select() notifications Eric Dumazet
2006-11-09  9:29           ` Evgeniy Polyakov
2006-11-09 18:51         ` Davide Libenzi
2006-11-09 19:10           ` Evgeniy Polyakov
2006-11-09 19:42             ` Davide Libenzi
2006-11-09 20:10               ` Davide Libenzi
2006-11-11 17:36   ` [take24 7/6] kevent: signal notifications Evgeniy Polyakov
2006-11-11 22:28   ` [take24 0/6] kevent: Generic event handling mechanism Ulrich Drepper
2006-11-13 10:54     ` Evgeniy Polyakov
2006-11-13 11:16       ` Evgeniy Polyakov
2006-11-20  0:02       ` Ulrich Drepper
2006-11-20  8:25         ` Evgeniy Polyakov
2006-11-20  8:43           ` Andrew Morton
2006-11-20  8:51             ` Evgeniy Polyakov
2006-11-20  9:15               ` Andrew Morton
2006-11-20  9:19                 ` Evgeniy Polyakov
2006-11-20 20:29           ` Ulrich Drepper
2006-11-20 21:46             ` Jeff Garzik
2006-11-20 21:52               ` Ulrich Drepper
2006-11-21  9:09                 ` Ingo Oeser
2006-11-22 11:38                 ` Michael Tokarev
2006-11-22 11:47                   ` Evgeniy Polyakov
2006-11-22 12:33                   ` Jeff Garzik
2006-11-21  9:53             ` Evgeniy Polyakov
2006-11-21 16:58               ` Ulrich Drepper
2006-11-21 17:43                 ` Evgeniy Polyakov
2006-11-21 18:46                   ` Evgeniy Polyakov
2006-11-21 20:01                     ` Jeff Garzik
2006-11-22 10:41                       ` Evgeniy Polyakov
2006-11-21 20:19                     ` Jeff Garzik
2006-11-22 10:39                       ` Evgeniy Polyakov
2006-11-22  7:38                     ` Ulrich Drepper
2006-11-22 10:44                       ` Evgeniy Polyakov
2006-11-22 21:02                         ` Ulrich Drepper
2006-11-23 12:23                           ` Evgeniy Polyakov
2006-11-23  8:52                         ` Kevent POSIX timers support Evgeniy Polyakov
2006-11-23 20:26                           ` Ulrich Drepper
2006-11-24  9:50                             ` Evgeniy Polyakov
2006-11-27 18:20                               ` Ulrich Drepper
2006-11-27 18:24                                 ` David Miller
2006-11-27 18:36                                   ` Ulrich Drepper
2006-11-27 18:49                                     ` David Miller
2006-11-28  9:16                                       ` Evgeniy Polyakov
2006-11-28 19:13                                         ` David Miller
2006-11-28 19:22                                           ` Evgeniy Polyakov
2006-12-12  1:36                                             ` David Miller
2006-12-12  5:31                                               ` Evgeniy Polyakov
2006-11-28  9:16                                 ` Evgeniy Polyakov
2006-12-13 13:21                           ` Tushar Adeshara
2006-12-13 13:27                             ` Evgeniy Polyakov
2006-11-22  7:33                   ` [take24 0/6] kevent: Generic event handling mechanism Ulrich Drepper
2006-11-22 10:38                     ` Evgeniy Polyakov
2006-11-22 22:22                       ` Ulrich Drepper
2006-11-23 12:18                         ` Evgeniy Polyakov
2006-11-23 22:23                           ` Ulrich Drepper
2006-11-24 10:57                             ` Evgeniy Polyakov
2006-11-27 19:12                               ` Ulrich Drepper
2006-11-28 11:00                                 ` Evgeniy Polyakov
2006-11-22 12:09                     ` Evgeniy Polyakov
2006-11-22 12:15                       ` Evgeniy Polyakov
2006-11-22 13:46                         ` Evgeniy Polyakov
2006-11-22 22:24                         ` Ulrich Drepper
2006-11-23 12:22                           ` Evgeniy Polyakov
2006-11-23 20:34                             ` Ulrich Drepper
2006-11-24 10:58                               ` Evgeniy Polyakov
2006-11-27 18:23                                 ` Ulrich Drepper
2006-11-28 10:13                                   ` Evgeniy Polyakov
2006-12-27 20:45                                     ` Ulrich Drepper
2006-12-28  9:50                                       ` Evgeniy Polyakov
2006-11-21 16:29 ` [take25 " Evgeniy Polyakov
2006-11-21 16:29   ` [take25 1/6] kevent: Description Evgeniy Polyakov
2006-11-21 16:29     ` [take25 2/6] kevent: Core files Evgeniy Polyakov
2006-11-21 16:29       ` [take25 3/6] kevent: poll/select() notifications Evgeniy Polyakov
2006-11-21 16:29         ` [take25 4/6] kevent: Socket notifications Evgeniy Polyakov
2006-11-21 16:29           ` [take25 5/6] kevent: Timer notifications Evgeniy Polyakov
2006-11-21 16:29             ` [take25 6/6] kevent: Pipe notifications Evgeniy Polyakov
2006-11-22 11:20               ` Eric Dumazet
2006-11-22 11:30                 ` Evgeniy Polyakov
2006-11-22 23:46     ` [take25 1/6] kevent: Description Ulrich Drepper
2006-11-23 11:52       ` Evgeniy Polyakov
2006-11-23 19:45         ` Ulrich Drepper
2006-11-24 11:01           ` Evgeniy Polyakov
2006-11-24 16:06             ` Ulrich Drepper
2006-11-24 16:14               ` Evgeniy Polyakov
2006-11-24 16:31                 ` Evgeniy Polyakov
2006-11-27 19:20                 ` Ulrich Drepper
2006-11-22 23:52     ` Ulrich Drepper
2006-11-23 11:55       ` Evgeniy Polyakov
2006-11-23 20:00         ` Ulrich Drepper
2006-11-23 21:49           ` Hans Henrik Happe
2006-11-23 22:34             ` Ulrich Drepper
2006-11-24 11:50               ` Evgeniy Polyakov
2006-11-24 16:17                 ` Ulrich Drepper
2006-11-24 11:46           ` Evgeniy Polyakov
2006-11-24 16:30             ` Ulrich Drepper
2006-11-24 16:49               ` Evgeniy Polyakov
2006-11-27 19:23                 ` Ulrich Drepper
2006-11-23 22:33     ` Ulrich Drepper
2006-11-23 22:48       ` Jeff Garzik
2006-11-23 23:45         ` Ulrich Drepper
2006-11-24  0:48           ` Eric Dumazet
2006-11-24  8:14             ` Andrew Morton
2006-11-24  8:33               ` Eric Dumazet
2006-11-24 15:26                 ` Ulrich Drepper
2006-11-24 13:07           ` Miquel van Smoorenburg
2006-11-24  0:14         ` Hans Henrik Happe
2006-11-24 12:05       ` Evgeniy Polyakov
2006-11-24 12:13         ` Evgeniy Polyakov
2006-11-27 19:43         ` Ulrich Drepper
2006-11-28 10:26           ` Evgeniy Polyakov
2006-11-30 19:14 ` [take26 0/8] kevent: Generic event handling mechanism Evgeniy Polyakov
2006-11-30 19:14   ` [take26 1/8] kevent: Description Evgeniy Polyakov
2006-11-30 19:14     ` [take26 2/8] kevent: Core files Evgeniy Polyakov
2006-11-30 19:14       ` [take26 3/8] kevent: poll/select() notifications Evgeniy Polyakov
2006-11-30 19:14         ` [take26 4/8] kevent: Socket notifications Evgeniy Polyakov
2006-11-30 19:14           ` [take26 5/8] kevent: Timer notifications Evgeniy Polyakov
2006-11-30 19:14             ` [take26 6/8] kevent: Pipe notifications Evgeniy Polyakov
2006-11-30 19:14               ` [take26 7/8] kevent: Signal notifications Evgeniy Polyakov
2006-11-30 19:14                 ` [take26 8/8] kevent: Kevent posix timer notifications Evgeniy Polyakov
2006-11-03 16:30 [take22 0/4] kevent: Generic event handling mechanism Jonathan Lemon
2006-11-05 20:47 ` Pavel Machek
2006-11-06 10:13   ` Evgeniy Polyakov
2006-11-06 10:16     ` Pavel Machek
2006-11-06 10:37       ` Evgeniy Polyakov
2006-11-06 12:58         ` Pavel Machek
2006-11-06 13:54           ` Evgeniy Polyakov

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=4549A261.9010007@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=drangon.mail@gmail.com \
    --cc=johnpol@2ka.mipt.ru \
    --cc=linux-kernel@vger.kernel.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox