From owner-freebsd-threads@FreeBSD.ORG Wed Oct 31 07:24:21 2007 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7B6916A419 for ; Wed, 31 Oct 2007 07:24:21 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 97FA013C4CB; Wed, 31 Oct 2007 07:24:21 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from [127.0.0.1] (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l9V7OFWX018639; Wed, 31 Oct 2007 07:24:17 GMT (envelope-from davidxu@freebsd.org) Message-ID: <47282DD6.2010406@freebsd.org> Date: Wed, 31 Oct 2007 15:25:10 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20070516 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Igor Sysoev References: <20071026063822.GA91344@rambler-co.ru> In-Reply-To: <20071026063822.GA91344@rambler-co.ru> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@FreeBSD.org Subject: Re: kqueue based thread pool X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Oct 2007 07:24:21 -0000 Igor Sysoev wrote: > The modern threads implementation works fine with program that requires > fair threads scheduling, like Apache and MySQL. > > However, there are programs (like varnish) that use FSM and thread pool. > The threads allow to run on SMP and reduce blocking on disk I/O. > These programs use an acceptor/listener thread and worker pool threads. > In this model it's preferable to have one RUNnable worker thread per CPU and > to start next one only when the current thread blocks. Also, when scheduler > chooses next thread to run it should get the more recently run (cache hot) > thread instead of fair scheduling. It's good to have some idle threads > in pool, those run very seldom when active threads are blocked on I/O, etc. > > Just wonder whether current scheduler is easy extendable to create thread > pool controlled by kqueue: that is the kernel acts as acceptor/listener > thread that wakes up worker threads waiting in kevent() ? > > I have thought your idea for a while, if I understandd correctly, I think you want FIFO scheduling which does not do preemption. The problem in current system is for 1:1 threading, doing realtime scheduling is not safe, kernel is not ready for realtime scheduling, application code can starve other parts of system, this is why SCHED_FIFO and SCHED_RR classes thread can only be created by root. you may try libkse which doing FIFO in userland, just don't use SYSTEM scope thread, it will work. I am not sure kqueue will work with threading, my brain tells me kqueue is not multi-thread safe. ;-) Regards, David Xu