f



nanosleep accuracy / threads

I have a client app that runs a high number of threads and pumps tcp/ip
requests to a server at high intensity.  To slow down the app, I've
tried to introduce nanosleep, but have found that it doesn't result in
predictable delays.  Is there another method to use on the threads that
would be more predictable?

Thanks.

0
morty3e (4)
10/27/2005 2:13:51 PM
comp.unix.programmer 10827 articles. 0 followers. kokososo56 (349) is leader. Post Follow

6 Replies
662 Views

Similar Articles

[PageSpeed] 57

morty3e@gmail.com schrieb:
> I have a client app that runs a high number of threads and pumps tcp/ip
> requests to a server at high intensity.  To slow down the app, I've
> tried to introduce nanosleep, but have found that it doesn't result in
> predictable delays.  Is there another method to use on the threads that
> would be more predictable?
> 
> Thanks.
> 

I suppose that you are using Linux due to your problem with the nanosleep().
The timer of the vanilla Kernel depends on the system speed and is thus
not quite precise. You could:
1. tune the system frequence high (1000 Hz max. since 2.6.12)
2. apply the Preemption-Realtime patch of Ingo Molnar.
http://people.redhat.com/mingo/realtime-preempt/
The timer usage of nanosleep is directly mapped to the ktimer of the
patch. It's a high resolution realtime clock and will hopefully meat
your requirement.

Good luck
Cheers
Luotao Fu
0
Luotao
10/27/2005 3:29:13 PM

morty3e@gmail.com wrote On 10/27/05 10:13,:
> I have a client app that runs a high number of threads and pumps tcp/ip
> requests to a server at high intensity.  To slow down the app, I've
> tried to introduce nanosleep, but have found that it doesn't result in
> predictable delays.  Is there another method to use on the threads that
> would be more predictable?

    For high accuracy you need a real-time system.  (What
"high accuracy" means is application-dependent.)

    To get a rate that's fairly good (another application-
dependent term), you could create a "governor" thread.  It
would check the current time with a high-resolution timer
(e.g., gethrtime() on Solaris), then sleep for a nominal
interval, then use the high-resolution timer to get the
actual time upon awakening.  From the actual elapsed time
and the desired message rate it would calculate the number
of messages that are now "due," and increment a semaphore
that many times.  Pseudocode:

	quota = 0;
	start = gethrtime();
	while (running) {
	    sleep_a_while();
	    goal = (gethrtime() - start) * message_rate;
	    increment_semaphore(goal - quota);
	    quota = goal;
	}

    Meanwhile, the message-generating threads spew requests
as fast as they can, but decrement the semaphore before each
transmission.  They'll wait until the governor says it's time
for more requests, and they will never exceed the quota.

    The overall effect will be a bit bursty: You'll have a
few moments of silence until the governor calls for more
traffic, then a flurry of requests as all the requestors
burn through the quota, then another interval of silence,
and so on.  If the governor's sleep intervals are brief
enough this may be acceptable.  You could also slow down the
requestors a bit by introducing sleeps as you've already done,
but with the governor throttling the overall rate of progress
you're no longer so dependent on the accuracy of the sleep
intervals.  You could even "tune" the requestors' nominal
sleep times by keeping track of how long a requestor thread
waits for the semaphore: if it always winds up waiting then
it's probably sleeping for too short a time, but if it never
waits it's probably sleeping too long.

    Whether any of this is tenable depends on just how tightly
you need to control the request generation rate.  As I said at
the beginning, for extremely tight control you'll need features
that go beyond what a general-purpose O/S is designed to deliver.

-- 
Eric.Sosman@sun.com

0
Eric
10/27/2005 3:52:58 PM
morty3e@gmail.com wrote:
> I have a client app that runs a high number of threads and pumps tcp/ip
> requests to a server at high intensity.  To slow down the app, I've
> tried to introduce nanosleep, but have found that it doesn't result in
> predictable delays.  Is there another method to use on the threads that
> would be more predictable?
> 
> Thanks.

You could try to count the requests you sent.
(maybe in the last n seconds)

HTH,
AvK
0
moi
10/29/2005 11:52:17 AM
I've been thinking of doing that, but using nanosleep() after reaching
that (one second) limit would still rely on nanosleep() and its
unpredictable results.

Here are some numbers I got when doing a quick test.

Delay,Write,Read,Puts,Threads,Read TPS
0,2,16,100,1,6250
1,100,109,100,1,917
10,102,111,100,1,901
100,138,150,100,1,667
1000,982,983,100,1,102
10000,994,995,100,1,101
10000,992,993,100,1,101
100000,993,994,100,1,101
1000000,1835,1836,100,1,54
10000000,10946,10947,100,1,9

0,12,55,1000,1,18182
1,993,994,1000,1,1006
10,1067,1076,1000,1,929
100,1034,1044,1000,1,958
1000,9927,9928,1000,1,101
10000,9991,9992,1000,1,100
10000,9996,9997,1000,1,100
100000,9993,9994,1000,1,100
1000000,19102,19103,1000,1,52
10000000,109707,109708,1000,1,9

0,13,34,100,10,29412
1,75,83,100,10,12048
10,80,88,100,10,11364
100,107,125,100,10,8000
1000,990,991,100,10,1009
10000,993,994,100,10,1006
10000,994,995,100,10,1005
100000,1001,1002,100,10,998
1000000,1711,1719,100,10,582
10000000,10942,10943,100,10,91

0,77,277,1000,10,36101
1,1337,1340,1000,10,7463
10,1270,1278,1000,10,7825
100,1221,1229,1000,10,8137
1000,9977,9978,1000,10,1002
10000,9993,9994,1000,10,1001
10000,9997,9998,1000,10,1000
100000,9996,9997,1000,10,1000
1000000,19066,19067,1000,10,524
10000000,109808,109809,1000,10,91

0
morty3e
11/3/2005 3:00:21 PM
<morty3e@gmail.com> wrote in message 
news:1130422431.532259.144650@g49g2000cwa.googlegroups.com...

>I have a client app that runs a high number of threads and pumps tcp/ip
> requests to a server at high intensity.  To slow down the app, I've
> tried to introduce nanosleep, but have found that it doesn't result in
> predictable delays.  Is there another method to use on the threads that
> would be more predictable?

    Why do you need to slow down the app? TCP/IP has its own pacing, you 
should be able to read/write data to the TCP/IP connections at full speed 
without any problem.

    DS


0
David
11/3/2005 7:15:40 PM
On 2005-11-03, David Schwartz <davids@webmaster.com> wrote:
[...]
>     Why do you need to slow down the app? TCP/IP has its own pacing, you 
> should be able to read/write data to the TCP/IP connections at full speed 
> without any problem.

Sometimes, there're some "funny" requirements saying that this
particular code must not process input faster than this and this :) 
For example we have multiple links, one link pushes lots of data, thus
pulling on itself CPU, bandwith etc. We want to slow it down. Another
example, our peer server is buggy, and if we feed the data too fast, then
that server hits some race condition and crashes. They can't fix the
server (commercial product), so instead we have to push data slower.

I guess there are lots of examples in real world that put the
requirement to slow down TCP stream. Fortunately, so far I didn't hit
the requirement to do it with nanosecond accuracy :)

-- 
Minds, like parachutes, function best when open
0
Andrei
11/4/2005 10:15:06 AM
Reply:

Similar Artilces:

Programmers, Programmers, Programmers, ...
As Steve Balmer correctly stated, while making his monkey dance, it is applications and hence programmers that make a platform. The fact though is that if you want to do professional programming, then Linux is the platform for you. I know that this statement will get the heckels up on a lot of trolls in C.O.L.A, but I have a recent experience that proves this. I am currently working for a Windows only house producing a system that receives and transmits around 1000 telegrams per second in each direction on a UDP socket, translates them into a different format and creates a log entry for each ...

Unix Admn. & Unix Programmers required urgently..!!
---------- Forwarded message ---------- From: krishnamohan Kola <krishnamohan.kola@paralogica.com> Date: Jul 1, 2008 10:12 PM Subject: Unix Admn. & Unix Programmers required urgently..!! To: kol.srinu@gmail.com Dear srinivas, Hi, Greetings...!!! Our clientele includes the Top 20 IT companies in India.At present we have Immediate Opening at CMM Level 5 Co. at Mumbai. We have an urgent requirement for following skill set: Open Position : 1) Unix Programmers(3 positions) Exp: 1 + yrs 2) Unix/Solaris Admins (4 positions) Exp: 1+ yrs 3) Solaris Admins (4 positions) Exp: 2-3 year...

thread, threading; how to kill a thread?
Greetings Pythonists; I have limited experience with threaded apps and plenty with old style forked heavyweight multi-processing apps. Using Python 2.3.3 on a Redhat 7.x machine. Wondering if there is a simple way from a main python program to kill a running thread? I see with the 'threading' module the way daemonic threads behave when the main program finishes. But suppose we have a simple thread running a function like; def timedLoop(): while True: time.sleep(10) doSomething() All I am trying to do is stop that thread immediatly from the main program and i...

Thread or not thread
Hello, i read some document that say enabling threads (in Bind 9.x compiling), giv= e less performance than disabling threads, in a 32 bit environment (with 2 = cpu), using Bind DLZ (with Postgresql DB). I found something here: http://zaphods.net/~zaphodb/high-performance-bind9.html Do you suggest enabling threads with DLZ or not? Thank you! Francesco= ...

Thread or threads.
thinking of writing a perl script with concurrent abilities. which Module is better 'Thread' or 'threads' ? thx. On Mon, 30 Jun 2008 05:24:19 -0700 (PDT), nadav <nadavh@gmail.com> wrote: >thinking of writing a perl script with concurrent abilities. >which Module is better 'Thread' or 'threads' ? > >thx. Thread (capital T) is obsolete. -- I'm not really a human, but I play one on earth. http://zentara.net/CandyGram_for_Mongo.html nadav wrote: > thinking of writing a perl script with concurrent abilities. > which Module is bette...

To thread or not to thread
My app needs to check a number of things on the web. This can be done in the background. I use idHTTP to pull data in. This process is broken down into small parts and the subroutinen are called in the OnIdle handler of the main form. I notice that sometimes idHTTP needs a considerable time to build the connection/fetch the data and the application doesn't repond to user actions during such periods. To cope with this I have now implemented the web data fetching in a thread with priority tpIdle. I think the problem of non-response has gone, ut it is difficult to test. Am...

To thread or not to thread ?
The threads of discussion about threads have been enlightening in exposing some of the low level issues which could possibly affect MT code and, more importantly, served also to bring awareness to the unsuspecting (me for one). It leaves me wondering if writing MT code is even to be pursued at this point in time, or at least "where's the guidebook to read is that will facilitate the writing of MT code without engaging compiler-level gotchas?". Can the low level issues be dealt with in the short term by following certain rules, perhaps platform-specific ones, or is robust MT code ...

threading a thread
I have a program written in Python that checks a class B network (65536 hosts) for web servers. It does a simple TCP socket connect to port 80 and times out after a certain periods of time. The program is threaded and can do all of the hosts in about 15 minutes or so. I'd like to make it so that I can check for other open ports (instead of just port 80) and I'd like to thread the port checks as well. Right now I'm just prototyping and the threaded hosts portion works very well for my needs. I'd just like to add a threaded ports check and wanted to know if anyone had don...

To thread or not to thread
Hello, I was recently reading an article on threading in python and I came across Global Interpreter Lock,now as a novince in python I was cusrious about 1.Is writing a threaded code in python going to perform well than a normal python code.If so on what basis can it performance be measured. 2.Is writing a threaded code in python better than a code written in C/C++ using PTHREADS. If someone can comment on these questions, it would be great. On 2005-07-28, Sidd <iamsidd@gmail.com> wrote: > I was recently reading an article on threading in python and I > came across Glo...

thread or threads ?
For some time now, I've been checking out tcl, tk, tls and threads from sourceforge. Recently, my cvs went berserk (I passed it a subdirectory with trailing slash for update, but I'm not sure if that was really the reason), and instead of updating just that directory, it checked out all modules. Among these modules was "thread". I checked for what was more recent, and it looked like thread had more recent checkins than threads. But "thread" doesn't even configure: > ../../../cvs/sourceforge/thread/configure checking for correct TEA configuration... ok (T...

UNIX Programmer
Title: Data Development Operations Support Analyst Salary: 70k Fulltime role A Reference Data Operations Support Analyst position involves a combination of operations support and development responsibilities in a financial services environment. Responsibilities include loading feeds from vendors into database applications on a predefined schedule. Vendor feeds provide data that must be validated, cross referenced against data already in the applications and then loaded Operations support responsibilities include: Responding to problems communicated via email, telephone call, bee...

About threading.Thread
Hello guys: I have an question on threading.Thread My code is here: File1: a.py import threading import time def hello(): while True: print('hello') threads =3D threading.enumerate() for thread in threads: print(thread.getName()) time.sleep(3) def fun(): a =3D threading.Thread(target=3Dhello(), name=3D'hello') print("a file: I won't display!") a.start() File2: b.py import time from a import fun fun() print("b file: I won't display!") When I run: python b.py (python version: 2.7.6, 3.3.5, 3.4....

US-NY: New York-C++/UNIX and UNIX/C Senior Developers/Programmers-Multithrea
************************************************************** JobCircle.com - Careers, Content and Community for Technology professionals in the Northeastern United States! Jobcircle.com provides resume submission, classified searches, eLearning, hundreds of career development articles, tech news, and more to tens of thousands of Technology professionals in your area - visit us today at http://www.jobcircle.com! !!! Voted a TOP 50 Career Web Site in 2002 by CareerXRoads !!! ************************************************************** Job Title: C++/UNIX and UNIX/C Senio...

Web resources about - nanosleep accuracy / threads - comp.unix.programmer

rough idling
Computers are kind of fast these days, which means a lot of little inefficiencies vanish from sight. In theory an idle system with nothing to ...

RDS display on a Raspberry Pi
Earlier I modified my radio to output raw bits from its RDS decoder chip. The radio already displays a Programme Service name, but for FM DX ...

arbitrary unix stuff
... - UUOC - ancient - - - Various - HOME " $@ " - echo/printf - set -e - test - tty defs - tty chars - $() vs ) - IFS - using siginfo - nanosleep ...

Linux-Kernel Archive: Re: [PATCH] msleep() with hrtimers
Hi, On Tue, 7 Aug 2007, Andrew Morton wrote: > > The current msleep is fine and doesn't need any "fixing". > > Not all the world is i386, _please_ ...

Tags : A Weird Imagination
A Weird Imagination About Comments Categories Tags Archives Tags 256 color terminal 65xx abort about alsa alsamixer amixer apropos apt apt-get ...

sleep(3): sleep for specified number of seconds - Linux man page
sleep() makes the calling thread sleep until seconds seconds have elapsed or a signal arrives which is not ignored.

modman.unixdev.net - Browse Manual: FreeBSD-5.4-RELEASE
My UNIXdev > My Account New Account About News Message Board Projects > CVS Browse Documentation > OS Manpages Java SE 1.5 API Java EE 1.4 API ...

signal(7) - Linux manual page
Linux supports both POSIX reliable signals (hereinafter "standard signals") and POSIX real-time signals. Signal dispositions Each signal has ...

Detailed Table of Contents for "The Linux Programming Interface"
(Look here for the abbreviated table of contents.) PREFACE 1 HISTORY AND STANDARDS 1.1 A Brief History of UNIX and C 1.2 A Brief History ...

System Interfaces: Table of Contents
The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition Copyright © 2001-2004 The IEEE and The Open Group Introduction Scope ...

Resources last updated: 2/7/2016 4:16:29 PM