#Project design help

23 messages · Page 1 of 1 (latest)

mortal needle
#

Currently I'm building a project that handle a serial analog data from a ECG-Sensor that being to my UDP Server, they comes at 400hz rate and my server is only 2 Core, 4GB Ram.

What is the best way to handle the udp streams correctly?

Currently my solution is:

UDP stream -> UDP handler receive -> send to ecg-data channel -> ECG Handler loop through the channel for data := range ecgChan -> Process the data -> Result

Is there a better solution?

steel ledge
#

what are you attempting to gain by using the channel? it's not totally clear to me where having two goroutines brings any benefit

#

not to say that it couldn't work, but when this is all the information you're asking us to work with, all we can do is discuss those pieces 😁

mortal needle
#

and more efficient

steel ledge
#

well, it would be fewer steps for the data to pass through, right?

mortal needle
steel ledge
#

synchronizing goroutines isn't free, and while that doesn't mean you should never use them, i'd really ask yourself why you're trying to use them

#

i think that question remains unanswered from yesterday

mortal needle
#

I just want to implement them and learn about it

#

but now the project have grown bigger, I guess it is time to remove

steel ledge
#

that's a totally legitimate want, but that may not be compatible with "what's the best way to design my project", which is what you asked

mortal needle
steel ledge
#

i would write the simplest code possible and deal with any problems as you identify them

#

there may be a point where goroutines come into the picture, but at that point you'll know why much more clearly

steel ledge
#

don't doubt how well just…writing a loop can work

#

it may seem too simple, but it will help you to form a more direct understanding of what's happening, and if something might need to change from that point

ebon anchor
#

One goroutine can handle A LOT of data especially with how lightweight protocol udp is

#

I’d also not think too much and implement multithreading only if you notice one goroutine is bottlenecking

steel ledge
#

i wouldn't think about it in terms of the goroutine itself being able to "handle" something, because at the end of the day it's not the goroutine that is executing code, it's the processor

#

a goroutine is just an execution context

#

what you need to ask yourself when you're considering adding goroutines in the mix is whether you need multiple execution contexts, not just that you need to "execute more"