doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Synchronous Emit #230

Open Jakobi-mirsk opened 2 years ago

Jakobi-mirsk commented 2 years ago

hi We are investigating a problem where sending using EmitAsync seems slow to actually send the request, when we are making many requests. Is is possible get a version where we can Emit synchronously?

Jakobi-mirsk commented 2 years ago

a follow up on this is that i just tested emitting a 1000 small packeges in 2 different ways. First way, was to use the Parallel object. This resulted in really slow performance of this library. the second way was to send the packages synchronously from the main thread of my test app. this showed good performance. How come we have this difference in performance. I would have thought that doing things in parallel would be faster.

doghappy commented 2 years ago

Hi, please show your test code. thank you very much🤗

Jakobi-mirsk commented 2 years ago

I don't have code that can easily be put in here but basically calling socket.EmitAsync in a while loop 1000 times is very fast compared to calling it from: Parallel.For(0, 1000, new Action((count) => socket.EmitAsync(....) })); usually Parallel is faster because it uses all the cores paralel, but in this case it is not.

jlareo commented 2 years ago

Even If you use parallel execution you have to consider that is being shared a socket connection, that by using some locks (to guarantee that a message will not be misformed), will slow down the send.

It's like many people trying to enter a train at the same time. It's faster making a queue. 😬

Jakobi-mirsk commented 2 years ago

thanks for the update, i will consider it