Best API for low latency

DDeaDo10/7/2022
I have a small client application that does simple calculations. Now i want to make it report the results to my asp server. Other clients in the same wifi network should take the results and also work on those calculations. So they have to exchange their results as fast as possible. The rest api is too slow for that though. I thought that a gRPC stream would be more suitable for this Task. UDP maybe? Does a faster API even help even if i want exchange data without a direct ethernet connection?
DDuke10/7/2022
why is a rest api too slow
DDeaDo10/7/2022
It seems that my application spends more time reporting the results, than actually calculating
Ttebeco10/7/2022
did you actually profile it ?
or it's more like a perception for now ?
DDuke10/7/2022
For what purpose does this have to be super fast
DDeaDo10/7/2022
The application should work on the traveling salesman problem, so in best case every calculation uses the results of the previous calcolation
FFyren10/7/2022
Work on the salesman problem? As in use the best algorithm for the problem, or try to find a better algorithm?
Unless you have a university level supercomputer then the latter will be pointless I think
FFyren10/7/2022
The different top algorithms for the problem are like 0.0001% apart in performance, and have been for years so it'll be hard to improve
Ttebeco10/7/2022
1.) did you actually profile it ? or you're making assumption ?
2.) what's your SLA ?
3.) did you ran TCPDUMP on server side ?
4.) did you ran TCPDUMP client side ?
5.) did you reconciliate to see where's the latency is ?
6.) how does all these result prouve the issue is realy at L7 lvl of kestrel ?
7.) did you tried to force H2 ?
8.) did you tied without wifi ?
DDeaDo10/7/2022
well i wont be able to create a better algorithm than anything that already exists, but thats not the point, im just trying things out
Ttebeco10/7/2022
hello ?
DDeaDo10/7/2022
1.) Yes
2.) No
3.) No
4.) No
5.) Yes
6.) ?
7.) No
8.) Yes
Ttebeco10/7/2022
you can't do 5 without 3 and 4
DDeaDo10/7/2022
sry pls give me some time i have to translate
Ttebeco10/7/2022
¯\_(ツ)_/¯
DDeaDo10/7/2022
i tried to measure it on client
Ttebeco10/7/2022
6: if you can't have 3 4 and 5 you can't tell about L7 (http)
Ttebeco10/7/2022
client means nothing
Ttebeco10/7/2022
because there's the network infra
Ttebeco10/7/2022
hence point 3 and 4
Ttebeco10/7/2022
if you measure only client side you measure notion relatable
Ttebeco10/7/2022
it can even be the client being slow
Ttebeco10/7/2022
and not the server
Ttebeco10/7/2022
it could be your network
DDeaDo10/7/2022
makes sense
Ttebeco10/7/2022
how did you profiled 1 ?
Ttebeco10/7/2022
please tell me you never used DateTime.Now
Ttebeco10/7/2022
if you used DateTime for anything in your computation you can throw your result
Ttebeco10/7/2022
network, especially lan is supposed to be ~1ms or less
DDeaDo10/7/2022
Stopwatch 😅
Ttebeco10/7/2022
DateTime precision is ~16ms
Ttebeco10/7/2022
stopwatch is "fine" but only if you make the full round
Ttebeco10/7/2022
because you can't trust clock
Ttebeco10/7/2022
which mean adding a stamp at each step
Ttebeco10/7/2022
and measure deviation
FFyren10/7/2022
Isn't there a github repo for benchmarks that could be helpful to determine the application code is not what's making it slow?
edit: found it - https://github.com/dotnet/BenchmarkDotNet
Ttebeco10/7/2022
with possibly a pre-round of average to get the clock drift
Ttebeco10/7/2022
I really think your issue is not the fact that it's a REST application
Ttebeco10/7/2022
it's either the way you bind
Ttebeco10/7/2022
or your network
Ttebeco10/7/2022
or your computation
Ttebeco10/7/2022
this is hard to bench network with that
FFyren10/7/2022
Yea I meant he could use it to rule out his application code before he moves on to infra
Ttebeco10/7/2022
sure
Ttebeco10/7/2022
you will need to tell more or show your actual repo link if you want more help
DDeaDo10/7/2022
If i start the client locally it's as fast as i expect it to be
Ttebeco10/7/2022
well then it's not the REST part
Ttebeco10/7/2022
try on LAN without WIFI
DDeaDo10/7/2022
yes ill do that first. I thought that a different API could eventually resolve my problems somewhere else. But I can see now that i should start somwhere else.
Ttebeco10/7/2022
maybe the way you expose/bind/parse the data is not helping
DDeaDo10/7/2022
i also have to change the way i report my results
Ttebeco10/7/2022
but if you're saying it's superfast on localhost
Ttebeco10/7/2022
why would that be the code issue just by using wifi ?
DDeaDo10/7/2022
currently my application stops calculating until it finished checking the results on the server
Ttebeco10/7/2022
it's too abstract at this point
DDeaDo10/7/2022
and thanks for those. Ill try checking all of these afterwards
DDeaDo10/7/2022
changing the way i report it could make the network issue less relevant
Ttebeco10/7/2022
there's A LOT of possible factor
Ttebeco10/7/2022
what's important is you load the app is to make your you draw all the round about that each packet does
Ttebeco10/7/2022
and when you make a measurment make sure to look at the graph
Ttebeco10/7/2022
between what point and what point
Ttebeco10/7/2022
and then accept that it's the sum of these
Ttebeco10/7/2022
and you can be 100% sure the repartition is not uniform
Ttebeco10/7/2022
so you need to either change measurmenet location
Ttebeco10/7/2022
or make multiple measurement at once
Ttebeco10/7/2022
and if you change something ... try to change at little at possible
Ttebeco10/7/2022
* never use Timer class
* never use DateTime class
Ttebeco10/7/2022
they are not precise AT ALL
Ttebeco10/7/2022
* never use await task.delay or Thread.sleep (because they rely on a timer, and thus not precise)
Ttebeco10/7/2022
use stuff like Bombardier or Benchmark.net if you need to time load
Ttebeco10/7/2022
or make a precise timed loop using spingwait + stopwathc if you need precise cadence
Ttebeco10/7/2022
using while(true){send} wihtout interval will simply DOS your network here or there and your mesurement will be invalid
Ttebeco10/7/2022
aka: you might saturate some infra / buffer and you would only measure how bad is your infra when your infra is dying <== is it really relevant ?
DDeaDo10/7/2022
Ok, thanks. There are quite a few thing i want to check before that.
Basically the only thing i know so far is that the entire thing is factor 10 slower if the client is running on a different machine than the server application. Ill adapt the measuring if the rougher issues are solved.
Ttebeco10/7/2022
WIFI is fucking slow in general TBH