From owner-freebsd-threads@FreeBSD.ORG Fri Oct 26 07:09:07 2007 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4275F16A418; Fri, 26 Oct 2007 07:09:07 +0000 (UTC) (envelope-from is@rambler-co.ru) Received: from relay0.rambler.ru (relay0.rambler.ru [81.19.66.187]) by mx1.freebsd.org (Postfix) with ESMTP id EF00513C4A7; Fri, 26 Oct 2007 07:09:06 +0000 (UTC) (envelope-from is@rambler-co.ru) Received: from relay0.rambler.ru (localhost [127.0.0.1]) by relay0.rambler.ru (Postfix) with ESMTP id C1E7B71F4; Fri, 26 Oct 2007 10:38:35 +0400 (MSD) Received: from localhost (is1.park.rambler.ru [81.19.64.121]) by relay0.rambler.ru (Postfix) with ESMTP id 8409E71EA; Fri, 26 Oct 2007 10:38:35 +0400 (MSD) Date: Fri, 26 Oct 2007 10:38:22 +0400 From: Igor Sysoev To: freebsd-threads@freebsd.org Message-ID: <20071026063822.GA91344@rambler-co.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: No virus found Cc: David Xu Subject: 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: Fri, 26 Oct 2007 07:09:07 -0000 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() ? -- Igor Sysoev http://sysoev.ru/en/