Mailing List Archive

Tool to measure ssh latency ("sshping") ?
Hi!

----

Before I start writing one myself...
... did anyone ever wrote a tool to measure the latency of a ssh
connection, a la "ping" ?

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
That gets...really complicated... Because what exactly do you want to
measure? Time to approx. beginning of the authentication exchange?
Time to get authenticated? Time to get a command executed (echo
hello? what shell?) ... anyway SmokePing has an SSH probe implemented
by running ssh-keyscan and measuring the time taken, this gets (as I
understand it) you time to roughly the beginning of authentication.

https://oss.oetiker.ch/smokeping/probe/SSH.en.html

On Thu, Jul 27, 2023 at 3:23?PM Roland Mainz <roland.mainz@nrubsig.org> wrote:
>
> Hi!
>
> ----
>
> Before I start writing one myself...
> ... did anyone ever wrote a tool to measure the latency of a ssh
> connection, a la "ping" ?
>
> ----
>
> Bye,
> Roland
> --
> __ . . __
> (o.\ \/ /.o) roland.mainz@nrubsig.org
> \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
> /O /==\ O\ TEL +49 641 3992797
> (;O/ \/ \O;)
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



--

"Genius might be described as a supreme capacity for getting its possessors
into trouble of all kinds."
-- Samuel Butler
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
Take a look at the metrics option in HPN-SSH. It does not, specifically,
do a ping but it can get you a lot of information about what is
happening in the TCP stack if that might help. It might be too
microlevel for what you are looking to do though. Essentially, it gives
you a periodic dump of the TCP_INFO struct (in Linux and BSD) on both
sides of the connection. That doesn't give you latency metrics in and of
itself though.

The metrics option could probably be extended to get the send/recv times
of the SSH_MSGs it sends out but, of course, that comes with the
overhead of processing and I'm not sure how much latency that, in and of
itself, would add.

Anyway, source code is at https://github.com/rapier/openssh-portable.
More information at https://psc.edu/hpn-ssh-home including ppas for rpms
and debs.

Chris


On 7/27/23 5:14 PM, Roland Mainz wrote:
> Hi!
>
> ----
>
> Before I start writing one myself...
> ... did anyone ever wrote a tool to measure the latency of a ssh
> connection, a la "ping" ?
>
> ----
>
> Bye,
> Roland
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
Okay, so let me amend that. The metrics option does have RTT values in
it. That's pretty close to what you'd get from a ping but I'm being
overly pedantic because it's not a userspace measurement. So the answer
is, sort of?



On 7/27/23 5:14 PM, Roland Mainz wrote:
> Hi!
>
> ----
>
> Before I start writing one myself...
> ... did anyone ever wrote a tool to measure the latency of a ssh
> connection, a la "ping" ?
>
> ----
>
> Bye,
> Roland
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
Also, keep in mind that point uses ICMP which often uses a slow path
through network hardware. So a ping implemented in SSH will likely be
interacting with the hardware differently. While the two values will
largely correspond there will be enough difference to cause comparisons
between the two to have larger error bars than you might like.

By the way, I'm assuming you're doing this to get latency overhead
associated with ssh packet processing. If not can you even on what you'd
like to find out?





On 7/27/23 5:14 PM, Roland Mainz wrote:
> Hi!
>
> ----
>
> Before I start writing one myself...
> ... did anyone ever wrote a tool to measure the latency of a ssh
> connection, a la "ping" ?
>
> ----
>
> Bye,
> Roland
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
I’ve had a good experience with the sshping tool (https://github.com/spook/sshping). It collects a bunch of samples and summarizes results nicely.

On Thu, Jul 27, 2023 at 6:04 PM, Chris Rapier <[rapier@psc.edu](mailto:On Thu, Jul 27, 2023 at 6:04 PM, Chris Rapier <<a href=)> wrote:

> Also, keep in mind that point uses ICMP which often uses a slow path
> through network hardware. So a ping implemented in SSH will likely be
> interacting with the hardware differently. While the two values will
> largely correspond there will be enough difference to cause comparisons
> between the two to have larger error bars than you might like.
>
> By the way, I'm assuming you're doing this to get latency overhead
> associated with ssh packet processing. If not can you even on what you'd
> like to find out?
>
> On 7/27/23 5:14 PM, Roland Mainz wrote:
>> Hi!
>>
>> ----
>>
>> Before I start writing one myself...
>> ... did anyone ever wrote a tool to measure the latency of a ssh
>> connection, a la "ping" ?
>>
>> ----
>>
>> Bye,
>> Roland
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
On Thu, Jul 27, 2023 at 11:28?PM Michael Loftis <mloftis@wgops.com> wrote:
> On Thu, Jul 27, 2023 at 3:23?PM Roland Mainz <roland.mainz@nrubsig.org> wrote:
> > Before I start writing one myself...
> > ... did anyone ever wrote a tool to measure the latency of a ssh
> > connection, a la "ping" ?
>
> That gets...really complicated... Because what exactly do you want to
> measure?

We want to profile some kind of ancient self-made RPC system, and
therefore we need to measure the time starting from writing a string
into ssh stdin, get on the remote side /bin/cat to send it back, and
then stop the clock when the string comes out of ssh's stdout. And
that in a form of endless loop, for around one hour (just to be sure
that the overhead of the ssh protocol negotiation details and network
noise don't ruin the measurements...).

Or short: Round-trip latency of data passed to a remote /bin/cat. And
that for every possible ssh -c cipher

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
while true
do
time echo test | ssh user@machine.somewhere <mailto:user@machine.somewhere> cat
done

But for a remote rpc service that requires low latency, take a look at multiplexing https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing and daemonize the Master connection


> On 28. 7. 2023, at 0:33, Roland Mainz <roland.mainz@nrubsig.org> wrote:
>
> On Thu, Jul 27, 2023 at 11:28?PM Michael Loftis <mloftis@wgops.com> wrote:
>> On Thu, Jul 27, 2023 at 3:23?PM Roland Mainz <roland.mainz@nrubsig.org> wrote:
>>> Before I start writing one myself...
>>> ... did anyone ever wrote a tool to measure the latency of a ssh
>>> connection, a la "ping" ?
>>
>> That gets...really complicated... Because what exactly do you want to
>> measure?
>
> We want to profile some kind of ancient self-made RPC system, and
> therefore we need to measure the time starting from writing a string
> into ssh stdin, get on the remote side /bin/cat to send it back, and
> then stop the clock when the string comes out of ssh's stdout. And
> that in a form of endless loop, for around one hour (just to be sure
> that the overhead of the ssh protocol negotiation details and network
> noise don't ruin the measurements...).
>
> Or short: Round-trip latency of data passed to a remote /bin/cat. And
> that for every possible ssh -c cipher
>
> ----
>
> Bye,
> Roland
> --
> __ . . __
> (o.\ \/ /.o) roland.mainz@nrubsig.org
> \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
> /O /==\ O\ TEL +49 641 3992797
> (;O/ \/ \O;)
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://www.google.com/url?q=https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev&source=gmail-imap&ust=1691102292000000&usg=AOvVaw3gpKfyFOLZGNpRePx3xCKW

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
Chris Rapier <rapier@psc.edu> wrote on Thu, 27 Jul 2023
at 18:04:47 EDT in <CA+8-fDLPnL7vSWn1aHB=SZDMVAqix_c9RY8+zmC0=Y8EHr_U2A@mail.gmail.com>:

> Also, keep in mind that point uses ICMP which often uses a slow path
> through network hardware. So a ping implemented in SSH will likely be

This claim about ICMP and slow paths is often-bandied about but is misleading and not really true in a way that is relevant.
But I want to take a moment to address it here, even if it's a bit off-topic.

Although one can always find some example of some device that behaves differently, for the most part, it only *generation* (not transiting or routing) of ICMP that may use a slow path. So that means if host A pings host B across 8 intermediate hops, the ping measures the fast-path network latency of the 8 hops plus the slow path latency of host B in responding. This is not generally a big deal.

A related source of confusion is a traceroute, where again it is the GENERATION of the response (an ICMP time exceeded message in response to what is usually a UDP probe packet, although not always) that is sometimes in the slow path (again, sometimes).

In a case where the latter is in the fast path (sometimes aka not sometimes) and the former is in the slow path, it means that if you run an ICMP ping from host A to the 7th hop between A and B, you'll see longer round-trip-times than the traceroute will show for the 7th hop from host A to host B (which is the time to transmit a UDP packet from host A towards host B with a time-to-live of 7 hops followed by the time for the 7th hop to generate the ICMP time exceeded message and send it back over the network).

(And a related source of confusion still is where the routing is asymmetric such that the path from A to B traverses intermediate nodes A->I1->I2->I3->I4->I5->I6->I7->I8->B but the path from A to I4 traverses a different path, say A->I1->I2->J1->J2->I4 such that a ping from A to B and a ping from A to I4 do not take the same path, so measuring round trips in the network may not be the sum of the apparent successive round trips to the nodes along the path.)


None of this is relevant when measuring the latency at the ssh layer, which has no meaningful "gotchas" with the network hardware when compared to measuring the latency of actual data transmitted over ssh, since the whole question of "fast paths" is about network nodes that don't look inside ssh packets. (Although we don't have an ssh timing infrastructure to give misleading results anyhow.)




Moving back towards the original question, at least a little bit, it is probably the case that Roland (the OP) does not want to measure the startup overhead of an SSH connection, so notional "time echo test | ssh user@host" solutions are unhelpful and actively misleading. The measurement needs to be done after the SSH connection is set up. Also, because of how TCP works, it's probably wise to think about how much data is being transferred. The timing for an RPC that transfers 100-byte query/responses will come out quite differently than one that transfers 100-megabyte query/responses (or asymmetric variants thereof), even when averaged over time, because of slow start and congestion windows and similar issues (and also because path/packet loss characterics may vary with packet size). So any measurement framework needs to keep that in mind and understand what the data size requirements are for whatever the test is simulating.

--
jhawk@alum.mit.edu
John Hawkinson
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
You are of course right, but maybe also wrong. This is why I recommended looking into multiplexing. If a regular SSH connection was used, there would be too much jitter caused by e.g. DNS cache expiring, randomness diminishing, fork()ing a new SSHD process (and the whole stack of PAM/systemd session/whatever), I think we all know that hiccups happen.
Then such test just needs to be modified to use that multiplexing, and only then it’s worthwhile to do any tuning (like disabling/enabling Nagle’s algorithm depending on what the RPC payloads would be, or tuning tcp windows etc.).

But I also have a nagging question of “is this a good idea?” in my head. This whole approach of using cat on a file and calling it RPC seems a bit naive, just like something I would do for some simple project, but not something that would be scalable or reliable or worthwhile asking a mailing list about :-))

Jan

> On 28. 7. 2023, at 1:56, John Hawkinson <jhawk@alum.mit.edu> wrote:
>
>
> Moving back towards the original question, at least a little bit, it is probably the case that Roland (the OP) does not want to measure the startup overhead of an SSH connection, so notional "time echo test | ssh user@host" solutions are unhelpful and actively misleading. The measurement needs to be done after the SSH connection is set up. Also, because of how TCP works, it's probably wise to think about how much data is being transferred. The timing for an RPC that transfers 100-byte query/responses will come out quite differently than one that transfers 100-megabyte query/responses (or asymmetric variants thereof), even when averaged over time, because of slow start and congestion windows and similar issues (and also because path/packet loss characterics may vary with packet size). So any measurement framework needs to keep that in mind and understand what the data size requirements are for whatever the test is simulating.

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
> while true
> do
> time echo test | ssh user@machine.somewhere
> <mailto:user@machine.somewhere> cat
> done

Well, shouldn't it be more like this?

while true
do
echo foobar
done | ssh user@machine > /dev/null


> But for a remote rpc service that requires low latency, take a look
> at multiplexing
> https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing and
> daemonize the Master connection

Yeah, that keeps a common SSH connection as well.



My €0.02: just use existing tools.

for nr in $(seq 0 3600)
do
id=$(date +%s.%N,$$,$nr | md5sum)
echo $id
sleep 1
done | strace -o /tmp/ssh.trace -tt -s 30 --trace=read,write >
/dev/null

Please note that "strace" does a dup() of STDIN, STDOUT, and STDERR,
so it's not fd 0,1,2 but 4,5,6 for me.


Sadly I couldn't get strace to log _only_ these fd --
but but by associating the read() and write() requests by the MD5-ID
it should be fairly easy to associate the matching calls,
and subtracting the timestamps should get a fairly accurate picture
of the latency.

(Also you should be able to see the communication to/from the ssh
process vs. the communication of ssh to the other host - ie. you can
measure "input encryption time, latency to remote answer, output
decryption time".)

That doesn't include processing _outside_ ssh, of course.


If the machine you're doing that on has a fairly recent linux kernel
running, you could also use bpftrace to get better filtered results.



_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Tool to measure ssh latency ("sshping") ? [ In reply to ]
On 27.07.23 23:14, Roland Mainz wrote:
> Before I start writing one myself...
> ... did anyone ever wrote a tool to measure the latency of a ssh
> connection, a la "ping" ?

Umh ... Nagios(/Icinga/.../Monitoring) plugins?

> [nagios@monitoring01 ~]$ PLUGINS="/usr/lib64/nagios/plugins"
> [nagios@monitoring01 ~]$ $PLUGINS/check_tcp -H 172.28.225.35 -p 22
> TCP OK - 0.002 second response time on 172.28.225.35 port 22|time=0.001993s;;;0.000000;10.000000
> [nagios@monitoring01 ~]$ $PLUGINS/check_ssh -p 22 172.28.225.35
> SSH OK - OpenSSH_7.4 (protocol 2.0) | time=0.020124s;;;0.000000;10.000000
> [nagios@monitoring01 ~]$ time $PLUGINS/check_by_ssh -H 172.28.225.35 -C "/bin/echo OK: SSH login succeeded"
> OK: SSH login succeeded
>
> real 0m0.788s
> user 0m0.051s
> sys 0m0.010s

https://pkgs.org/search/?q=nagios-plugins

Kind regards,
--
Jochen Bern
Systemingenieur

Binect GmbH