std.net.curl : Performance

Vino akashvino79 at gmail.com
Mon Nov 9 19:55:07 UTC 2020


Hi All,

   Request your help to on how to improve the performance of the 
below code.

import std.conv: to;
import std.net.curl : get, HTTP, CurlOption;
import std.parallelism: parallel;
import std.range: chain, only;
import std.typecons: Tuple, tuple;

void main ()
{
  Array!(Tuple!(int,string)) apidata;
  Row[] result;
  string apihost = "abc.com"; int apiport = 1830; string apiuri = 
/getdata;
  string apiuser = "user"; string apipass = "pass";
  foreach(i, k; parallel(result,1))
     {
       string url = chain(apihost, only(':'), to!string(apiport), 
apiuri).to!string;
       string usrpass = chain(apiuser, only(':'), 
apipass).to!string;
       auto https = HTTP();
       https.handle.set(CurlOption.buffersize, 512000);
       https.handle.set(CurlOption.userpwd, usrpass);
       https.handle.set(CurlOption.connecttimeout, 600);
       https.handle.set(CurlOption.tcp_nodelay, 1);
       https.handle.set(CurlOption.http_version, 2);
       https.handle.set(CurlOption.sslversion,  1;
       https.handle.set(CurlOption.use_ssl,  3);
       https.handle.set(CurlOption.ssl_verifypeer, 0);
       https.handle.set(CurlOption.url, url);
       https.method(HTTP.Method.get);
       https.StatusLine st;
       https.onReceiveStatusLine = (https.StatusLine st) { if 
(st.code != 200) { throw new Exception(st.reason); } };
       ubyte[] content;
       https.onReceive = (ubyte[] data) { content ~= data; return 
data.length; };
       https.perform();
       scope(failure) { https.shutdown; exit(-4); } scope(exit) 
https.shutdown;
       apidata.insert(tuple(seq, cast(string) content));
  }
  return apidata[].sort;
}

From,
Vino.B


More information about the Digitalmars-d-learn mailing list