curl-library
Boost::thread and libcurl
Date: Fri, 29 Apr 2011 17:30:03 -0700
Hi,
I have a small app written in C++ using boost::thread and in each
thread I GET a url and then collect the TOTAL_TIME for the call.
For some reason, the total time to complete the request is getting
higher in direct proportion with the number of threads(however, the
start time, doesn't fluctuate the same way ) :
st = 0.555129 tt = 1.410327
st = 0.497024 tt = 1.532519
st = 0.573047 tt = 1.681278
st = 0.526047 tt = 1.682707
st = 0.564088 tt = 1.691731
st = 0.581234 tt = 1.700273
st = 0.590450 tt = 1.702298
st = 0.596590 tt = 1.709537
st = 0.607918 tt = 1.734643
st = 0.509376 tt = 1.766935
st = 0.550980 tt = 1.922635
st = 0.590006 tt = 1.923356
st = 0.517195 tt = 2.016058
st = 1.713784 tt = 2.165693
st = 2.381155 tt = 2.629392
st = 2.365868 tt = 2.626579
st = 0.650427 tt = 3.460629
st = 1.122680 tt = 3.676684
st = 0.933988 tt = 3.945191
st = 3.229636 tt = 3.976624
st = 3.229090 tt = 3.975153
st = 0.830803 tt = 3.977385
st = 0.960128 tt = 3.997808
st = 0.698784 tt = 4.051275
st = 1.152903 tt = 4.177454
st = 0.848899 tt = 4.198260
st = 3.238565 tt = 4.203931
st = 1.019463 tt = 4.217049
st = 0.856870 tt = 4.368731
st = 1.661901 tt = 4.463512
st = 0.898374 tt = 4.575344
st = 0.849091 tt = 4.579787
st = 0.729995 tt = 4.585755
st = 0.643323 tt = 4.590226
st = 0.873924 tt = 4.586048
st = 0.637212 tt = 4.600180
st = 0.896408 tt = 4.594404
st = 1.047880 tt = 4.601875
st = 0.614152 tt = 4.624312
st = 0.770148 tt = 4.623168
st = 0.806639 tt = 4.703964
st = 0.976620 tt = 4.756329
st = 1.173377 tt = 4.751551
st = 0.846361 tt = 4.992248
st = 1.006075 tt = 5.106161
#include <boost/thread/thread.hpp>
#include<curl/curl.h>
#include <iostream>
int count = 0;
boost::mutex mutex;
boost::thread_group threads;
size_t default_callback(void *p, size_t n, size_t l, void *d) {
(void)p;
(void)d;
return n*l;
}
void increment_count()
{
CURL* handle;
CURLcode res;
double time1,time2;
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, default_callback);
curl_easy_setopt(handle, CURLOPT_URL, "http://www.google.com");
res = curl_easy_perform(handle);
mutex.unlock();
if(CURLE_OK == res){
curl_easy_getinfo(handle, CURLINFO_STARTTRANSFER_TIME, &time1);
curl_easy_getinfo(handle, CURLINFO_TOTAL_TIME, &time2);
}
boost::mutex::scoped_lock lock(mutex);
std::cout << std::fixed << "st = " << time1 << "\t\t" << "tt = "
<< time2 << std::endl;
}
void f(){
for (int i = 0; i < 10; ++i) {
threads.create_thread(&increment_count);
}
}
int main(int argc, char* argv[])
{
int j = 10;
while(j-->0){
boost::thread t = boost::thread(&f);
t.join();
}
threads.join_all();
}
Since all threads are spawned about the same time ( 10 at each time )
-- it is observed that every 10 threads the latency reported increases
Any suggestions on what could cause this ?
Thanks,
Radu
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-30