From libssh2-devel-bounces@cool.haxx.se  Tue Aug 15 14:38:42 2017
Return-Path: <libssh2-devel-bounces@cool.haxx.se>
Received: from www.haxx.se (mail [127.0.0.1])
	by giant.haxx.se (8.15.2/8.15.2/Debian-4) with ESMTP id v7FCc3Ce005990;
	Tue, 15 Aug 2017 14:38:34 +0200
Received: from EUR03-AM5-obe.outbound.protection.outlook.com
 (mail-am5eur03olkn0824.outbound.protection.outlook.com
 [IPv6:2a01:111:f400:fe08:0:0:0:824])
 by giant.haxx.se (8.15.2/8.15.2/Debian-4) with ESMTP id v7FCc2fw005961
 for <libssh2-devel@cool.haxx.se>; Tue, 15 Aug 2017 14:38:03 +0200
Received: from VE1EUR03FT030.eop-EUR03.prod.protection.outlook.com
 (10.152.18.57) by VE1EUR03HT247.eop-EUR03.prod.protection.outlook.com
 (10.152.19.132) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1304.16; Tue, 15
 Aug 2017 12:37:47 +0000
Received: from AM2PR02MB0708.eurprd02.prod.outlook.com (10.152.18.52) by
 VE1EUR03FT030.mail.protection.outlook.com (10.152.18.66) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id
 15.1.1304.16 via Frontend Transport; Tue, 15 Aug 2017 12:37:47 +0000
Received: from AM2PR02MB0708.eurprd02.prod.outlook.com
 ([fe80::595:763b:df3e:9f84]) by AM2PR02MB0708.eurprd02.prod.outlook.com
 ([fe80::595:763b:df3e:9f84%13]) with mapi id 15.01.1341.020; Tue, 15 Aug 2017
 12:37:47 +0000
From: William Newbery <wnewbery@hotmail.co.uk>
To: "libssh2-devel@cool.haxx.se" <libssh2-devel@cool.haxx.se>
Subject: Reducing latency for exec commands
Thread-Topic: Reducing latency for exec commands
Thread-Index: AQHTFcCzH8WFqAEtxk+yDPNifBaaSg==
Date: Tue, 15 Aug 2017 12:37:47 +0000
Message-ID: <AM2PR02MB0708345C9A59BF3389D1110D958D0@AM2PR02MB0708.eurprd02.prod.outlook.com>
Accept-Language: en-GB, en-US
Content-Language: en-GB
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
authentication-results: cool.haxx.se; dkim=none (message not signed)
 header.d=none; cool.haxx.se; dmarc=none action=none header.from=hotmail.co.uk; 
x-incomingtopheadermarker: OriginalChecksum:35C1F4FFD0A0371AA0FBC0F9EC217E0B55DD199D083C121D6DF1A9AEE4342ED3;
 UpperCasedChecksum:B42B8F463338684FAD5045078756312B08720D9830A672A746DDBD5F96AC71D4;
 SizeAsReceived:7103; Count:44
x-ms-exchange-messagesentrepresentingtype: 1
x-tmn: [Zt+Mt7mi3+hRAGRdKvydHG3omBSpm7QB]
x-ms-publictraffictype: Email
x-microsoft-exchange-diagnostics: 1; VE1EUR03HT247;
 7:vtBFv9a7CpsmUava7OXf4SOhPCs8TtdnqK8dInGdF1EdxuSPMKfyyHPnvYPCcUI/yxpyPNaKozAWidwOlGV9lzAGVSkeZtZw+1KY1OVw2dJyeUsfZPiKLYXtwvy2d4I1FwhQjKG4brHKasL7P40eeth0ACZlUSP/x5kQO+hw+kZGTpjXu0QR4SSG4YMOIIir1KeRFX0BjwNjat8mC1IX+2pR2vm+YunyT/b5MpM3ztYQNemwEvONaxx9S55+tfcPZ8IaBZbb2V9ZD8paLENhkRXXfTLEbvQSEMVMn8H65PTRQwBLX8rh1MRGmqF+89e31HAwzOCPtVDJaVcEu81Q5btq8Y782FKQMif+z5dhHola1YC79i+DRP992MQEwlwZ4I2NtgP9/pdZQp/ZJNBDdwsMDQvfPjLYmivnKM3/e9PbV9YaHeL8OWZpYXSUqfsNHXrfG4uHtQrbqGFlVJohUgW0ZNbdWSQcGGz8qIRhpIZ/dxTCyqRY+4tjJMB1fuot8s3sGntWFKynXH+WVr4L8N2jdFS5/E85iG/BrRpQZnuvCHsZh86dOEeO93ELSbdxt+X3JLIhoNG4C5/fuoLx4QnNVRpEd7ZZbjM7rgl8eajMxjVRrq+rJP/qXhqjiYHuncosqftgMGwMQ5RVGXAUcO/gG0frzv+YZS3blu2+qZl7m1AlnSTke4YfsEhxa3uijHFj1CU2AVqw8i2RHwyAPZ6zMxdzKFtiyaVwP6Q1/3QDFFSjSvuBEen4ctSNorjh26ZI8CTA43AF9x6pkNh8ZA==
x-incomingheadercount: 44
x-eopattributedmessage: 0
x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004);
 DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR03HT247;
 H:AM2PR02MB0708.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; 
x-ms-office365-filtering-correlation-id: 9957544c-75b1-43d4-fd55-08d4e3da6f54
x-microsoft-antispam: UriScan:; BCL:0; PCL:0;
 RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(300000503095)(300135400095)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322377)(1601125374)(1603101448)(1701031045)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);
 SRVR:VE1EUR03HT247; 
x-ms-traffictypediagnostic: VE1EUR03HT247:
x-exchange-antispam-report-test: UriScan:(158342451672863);
x-exchange-antispam-report-cfa-test: BCL:0; PCL:0;
 RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(444000031);
 SRVR:VE1EUR03HT247; BCL:0; PCL:0;
 RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);
 SRVR:VE1EUR03HT247; 
x-forefront-prvs: 04004D94E2
spamdiagnosticoutput: 1:99
spamdiagnosticmetadata: NSPM
MIME-Version: 1.0
X-OriginatorOrg: outlook.com
X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Aug 2017 12:37:47.4424 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Internet
X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT247
X-BeenThere: libssh2-devel@cool.haxx.se
X-Mailman-Version: 2.1.22
Precedence: list
List-Id: libssh2 development <libssh2-devel.cool.haxx.se>
List-Unsubscribe: <https://cool.haxx.se/cgi-bin/mailman/options/libssh2-devel>, 
 <mailto:libssh2-devel-request@cool.haxx.se?subject=unsubscribe>
List-Archive: <http://cool.haxx.se/pipermail/libssh2-devel/>
List-Post: <mailto:libssh2-devel@cool.haxx.se>
List-Help: <mailto:libssh2-devel-request@cool.haxx.se?subject=help>
List-Subscribe: <https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel>, 
 <mailto:libssh2-devel-request@cool.haxx.se?subject=subscribe>
Reply-To: libssh2 development <libssh2-devel@cool.haxx.se>
Content-Type: multipart/mixed; boundary="===============0458932073=="
Errors-To: libssh2-devel-bounces@cool.haxx.se
Sender: "libssh2-devel" <libssh2-devel-bounces@cool.haxx.se>

--===============0458932073==
Content-Language: en-GB
Content-Type: multipart/alternative;
	boundary="_000_AM2PR02MB0708345C9A59BF3389D1110D958D0AM2PR02MB0708eurp_"

--_000_AM2PR02MB0708345C9A59BF3389D1110D958D0AM2PR02MB0708eurp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,


I have some commands I want to run with exec that take just a couple of ms =
to output a KB or two and exitstatus (OpenSSH server). However when testing=
 over the network I am finding it takes a lot more than the ping time betwe=
en the systems.


Since I wanted the exitstatus for the command it seems I need a new channel=
 each time, so currently I have:


    channel =3D libssh2_channel_open_session(session);
    libssh2_channel_exec(channel, "echo Example");
    while (libssh2_channel_read(channel, buffer, len) > 0) ...
    libssh2_channel_close(channel);
    libssh2_channel_get_exit_status(channel);
    libssh2_channel_free(channel);

With about a 28ms ping time, "libssh2_channel_open_session" takes about 90m=
s, and "libssh2_channel_exec" takes about 30ms. The rest takes less than 1m=
s.

I tried setting TCP_NODELAY on my socket which got the open session down to=
 30ms. I couldnt find any reference to setting that for libssh2 (e.g. the e=
xamples dont do this) and am not certain if it risks creating other problem=
s.


Is there any other performance enhancements that can be made? I am consider=
ing pre-emptively opening channels during idle times so that I can immediat=
ely go to libssh2_channel_exec which looks to avoid the round trips, but ag=
ain its unclear if having many unused channels is considered OK.


Thanks,

--_000_AM2PR02MB0708345C9A59BF3389D1110D958D0AM2PR02MB0708eurp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi=
n-bottom:0;} --></style>
</head>
<body dir=3D"ltr">
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;font=
-family:Calibri,Helvetica,sans-serif;" dir=3D"ltr">
<p>Hi,</p>
<p><br>
</p>
<p>I have some commands I want to run with exec that take just a couple of =
ms to output a KB or two and exitstatus (OpenSSH server). However when test=
ing over the network I am finding it takes a lot more than the ping time be=
tween the systems.</p>
<p><br>
</p>
<p>Since I wanted the exitstatus for the command it seems I need a new chan=
nel each time, so currently I have:</p>
<p><br>
</p>
<p></p>
<div><span style=3D"font-size: 12pt;">&nbsp; &nbsp; channel =3D libssh2_cha=
nnel_open_session(session);</span><br>
</div>
<div>&nbsp; &nbsp; libssh2_channel_exec(channel, &quot;echo Example&quot;);=
</div>
<div>&nbsp; &nbsp; while (libssh2_channel_read(channel, buffer, len) &gt; 0=
) ...</div>
<div>&nbsp; &nbsp; libssh2_channel_close(channel);</div>
<div>&nbsp; &nbsp; libssh2_channel_get_exit_status(channel);</div>
<div>&nbsp; &nbsp; libssh2_channel_free(channel);</div>
<div><br>
</div>
<div>With about a 28ms ping time, &quot;<span style=3D"font-family: Calibri=
, Helvetica, sans-serif, EmojiFont, &quot;Apple Color Emoji&quot;, &quot;Se=
goe UI Emoji&quot;, NotoColorEmoji, &quot;Segoe UI Symbol&quot;, &quot;Andr=
oid Emoji&quot;, EmojiSymbols; font-size: 16px;">libssh2_channel_open_sessi=
on&quot;
 takes about 90ms, and &quot;libssh2_channel_exec&quot; takes about 30ms. T=
he rest takes less than 1ms.</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;"><br>
</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;">I tried setting TCP_NODELAY on my socket which got the open
 session down to 30ms. I couldnt find any reference to setting that for lib=
ssh2 (e.g. the examples dont do this)&nbsp;and am not certain if it risks c=
reating other problems.</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;"><br>
</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;"><br>
</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;">Is there any other performance enhancements that can be made?
 I am considering pre-emptively opening channels during idle times so that =
I can immediately go to&nbsp;<span style=3D"font-family: Calibri, Helvetica=
, sans-serif, EmojiFont, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoj=
i&quot;, NotoColorEmoji, &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&q=
uot;, EmojiSymbols; font-size: 16px;">libssh2_channel_exec
 which looks to avoid the round trips, but again its unclear if having many=
 unused channels is considered OK.</span></span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;"><br>
</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;"><br>
</span></div>
<div><span style=3D"font-family: Calibri, Helvetica, sans-serif, EmojiFont,=
 &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, NotoColorEmoji,=
 &quot;Segoe UI Symbol&quot;, &quot;Android Emoji&quot;, EmojiSymbols; font=
-size: 16px;">Thanks,</span></div>
<p></p>
</div>
</body>
</html>

--_000_AM2PR02MB0708345C9A59BF3389D1110D958D0AM2PR02MB0708eurp_--

--===============0458932073==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbGlic3NoMi1k
ZXZlbCBodHRwczovL2Nvb2wuaGF4eC5zZS9jZ2ktYmluL21haWxtYW4vbGlzdGluZm8vbGlic3No
Mi1kZXZlbAo=

--===============0458932073==--

