cURL에서 웹 페이지를 빨리 다운 받는 팁이 있을까요?

rootroot의 이미지

간단하게 libcurl을 이용해서 rss 구독기를 제작 중 입니다.

일단 주소대로 페이지를 하나씩 읽어온 다음,

하나씩 파싱한 후 파싱한 정보를 한대로 묶어서 리스트를 만들고 보여주는 식인데..

리스트가 적으면 상관없지만 구독할 리스트가 많아지면 많아질수록 읽어 오는 속도가 상당히 느리더군요,

(전체적으로 느린 것 보다 초기 화면에 뜨는 속도가 느립니다....)

다른 구독기랑 비교해봤는데 yarssr도 일일이 읽어오는지 많아질수록 느려지더라고요.

하지만 akregator는 피드를 한꺼번에 읽어온 다음 한꺼번에 파싱하는지 상당히 빠른 속도를 보이더군요.

(아니면 사용하는 라이브러리가 달라서 그런지도 모르겠습니다.)

그래서 질문드리는데 웹 문서를 대량으로 한꺼번에 읽어오는 방식이나

빠르게 문서를 읽어오는 라이브러리를 아시면 조언 좀 해주시면 감사하겠습니다.

아래는 제 소스 중 웹에서 소스 긁어 오는 함수인데 어떻게 수정하면 좀 더 빠를 수 있을까요?(c 소스)

RSS_FEED* url_get_xml(gchar* url)
{
CURL *curl_handle;
RSS_FEED* rss;
BUFFER chunk;
chunk.memory = g_malloc(1);
chunk.size = 0;

curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_memory_callback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

puts("읽어오기 시작!");
curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
puts("읽어오기 완료!");

rss = xml_parser(chunk.memory, chunk.size+1); // 읽어온 걸 파싱함

xmlCleanupParser();
xmlMemoryDump();

if(chunk.memory)
free(chunk.memory);

return rss;

}

dalgarak의 이미지

소극적인 방법으로는 curl_easy_setopt()에 CURLOPT_TCP_NODELAY 옵션을 줘서 nagle algorithm을 끄는 방법을 쓸 수 있을 것이고,
적극적인 방법으로는 fetch를 할 스레드와 parsing을 할 스레드를 분리하고 개별적으로 처리하도록 하는 방법을 쓰는게 좋을 것입니다.

rootroot의 이미지

ibm developworks에서 비슷한걸 슬쩍 봤었는데 지금 써봐야겠습니다.

답변 감사합니다!

linusix의 이미지

아무래도 여러개를 읽어야한다면 multi 핸들을 써서 curl 을 구현하시고 (소켓 select 개념입니다)

그 다음에 스레드를 생각해보시는게 좋겠죠

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.