# libcurl multi interface problem

**URL:** <https://community.unix.com/t/libcurl-multi-interface-problem/268905>\
**Category:** Programming\
**Created:** [July 5, 2010, 6:34pm UTC](https://community.unix.com/t/libcurl-multi-interface-problem/268905 "2010-07-05T18:34:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![clalfa](https://community.unix.com/letter_avatar/clalfa/32/6_449c533f586939b6e5f246632a46421f.png) [@clalfa](https://community.unix.com/u/clalfa)\
**Post date:** [July 5, 2010, 6:34pm UTC](https://community.unix.com/t/libcurl-multi-interface-problem/268905/1 "2010-07-05T18:34:11Z")

</div>

Hello, I'm trying to use libcurl multi interface to fetch several data in parallel. I would expect this to be faster than performing repeated fetches using the easy interface, but for some reason I can't obtain any speed up at all: using the multi interface actually turns out to be MUCH slower than launching several sequential "easy" requests.  
This is the code that actually performs the requests:

```nohighlight
  curlmh_ = curl_multi_init();
  int min_req = MIN(n_req_, urls_.size());
  CURL** curleh = new CURL*[min_req];
  
  // create min_req easy handles, to be added to a single multi handle
  for (int i=0; i<min_req; i++) {
    curleh = curl_easy_init();
    curl_easy_setopt (curleh, CURLOPT_URL, urls_.c_str());
    curl_easy_setopt (curleh, CURLOPT_WRITEFUNCTION, fetcher_thread::write_data);
    curl_multi_add_handle (curlmh_, curleh);
  }

  int active, curl_res, fd_res, max_fd;
  fd_set fds, fdsw, fdse;
  struct timeval timeout;
  timeout.tv_sec = 5;
  timeout.tv_usec = 0;

  do {
    do {
      curl_res = curl_multi_perform (curlmh_, &active);
    }
    while ( curl_res == CURLM_CALL_MULTI_PERFORM );

    FD_ZERO (&fds); FD_ZERO (&fdsw); FD_ZERO (&fdse);

    max_fd = 0;
    fd_res = curl_multi_fdset (curlmh_, &fds, &fdsw, &fdse, &max_fd);
    if ( max_fd == -1 ) {
      continue;
    }

    do {      
      fd_res = select (max_fd+1, &fds, &fdsw, &fdse, (struct timeval*)NULL);
    }
    while ( fd_res == -1 && errno == EINTR );      

    msleep(100); // I'd like to do other useful stuff meanwhile...
  }
  while ( curl_res == CURLM_OK && active > 0 );

  // operations finished, doing the cleanup
  for (int i=0; i<min_req; i++) {
    curl_multi_remove_handle (curlmh_, curleh);
    curl_easy_cleanup (curleh);
  }
  curl_multi_cleanup(curlmh_);  

```

I am using libcurl version 7.20.0-r2 under Gentoo Linux.

Any help/suggestion/idea would be really appreciated.  
Thank you

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 6, 2010, 10:01am UTC](https://community.unix.com/t/libcurl-multi-interface-problem/268905/2 "2010-07-06T10:01:00Z")

</div>

What is msleep?

---

<div class="post-metadata">

**Author:** ![clalfa](https://community.unix.com/letter_avatar/clalfa/32/6_449c533f586939b6e5f246632a46421f.png) [@clalfa](https://community.unix.com/u/clalfa)\
**Post date:** [July 6, 2010, 12:49pm UTC](https://community.unix.com/t/libcurl-multi-interface-problem/268905/3 "2010-07-06T12:49:48Z")

</div>

msleep makes the process wait for a given amount of milliseconds.  
I expect this not to slow down the requests, since this interface is by definition asynchronous. Anyway, removing that call does not help to avoid the problem, since repeated calls to easy\_perform on single easy\_handles are still faster...
