cURL / Mailing Lists / curl-library / Single Mail

curl-library

GetTickCount vs QueryPerformanceCounter

From: Igor Novoseltsev <IgorN_at_radvision.com>
Date: Thu, 20 May 2010 12:27:57 +0300

Hello,

 

My application implements unified communication client. As a part of its
activity, it performs HTTP transactions using the libcurl.

Sometimes the application get stuck. Note I use multi interface and
asynchronous mode (curl_multi_socket).

 

While investigating the issue, I found that the problem appears when the
activity timer asked by the libcurl, fires before the libcurl expects it
to expire. For example, the libcurl asked for 2 msec, and it's fires
after 1.5 msec for example. As a result the update_timer, called from
the curl_multi_socket (called by me on timer expiration), doesn't
update the splaytree. In that case the multi->timetree->key will be the
same node it was before the timer was run (multi->timetree->key ==
multi->timer_lastcall). This causes the update_timer to return without
asking application for additional 0.5(actually 1) msec !
 See

 

if(Curl_splaycomparekeys(multi->timetree->key, multi->timer_lastcall) ==
0)

    return 0;

 

check in update_timer.

 

If no network events should occur, the application will stuck, since
activity timer doesn't run.

 

Now you will probably ask, why the timer fires before the asked time.

The answer is: timer thinks that the asked interval expired!

My application uses WSAAsyncSelect and QueryPerformanceCounterd to
implement timers.

The libcurl uses GetTickCount (called from curlx_tvnow) to track the
elapsed time.

It is appears that the GetTickCount much less precise!

Please find the attached code that shows the difference!

This code runs loop, where each iteration sleeps for 2 msec (uses Sleep
system call) and prints the time elapsed since last iteration.

It uses two ways: GetTickCount and QueryPerformanceCounterd. The last
gives 2 msec at every iteration, when the first varies from zero to 16!

 

What do you think of this problem?

Is this possible to move the libcurl to use the
QueryPerformanceCounterd?

 

Thank you,

Igor

 

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

Received on 2010-05-20