Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using goPool to process messages #151

Closed
jdbruijn opened this issue Aug 17, 2020 · 4 comments
Closed

Using goPool to process messages #151

jdbruijn opened this issue Aug 17, 2020 · 4 comments
Labels
question Further information is requested

Comments

@jdbruijn
Copy link
Collaborator

I'm trying to get the goPool option for the DTLS server to work with ants but don't quite get how I'm supposed to use it. My end goal is to be able to process connections/requests in parallel as the the handler currently (without goPool) seems to be handled serial. I've read in the documentation on the WithGoPool function that it can be used with ants to spawn go routines.

@jkralik Could you please provide an example of how to use dtls.NewServer with dtls.WithGoPool using ants?

Regarding the go pool, I expect that it only applies to the handler and thus not to the DTLS handshake, as seems to be called in client connection Process function (here), is that correct? And, depending on the answer, would it be possible to to process DTLS handshakes in parallel too? The only hint I have that the DTLS handshakes not in parallel now is based on the DTLS trace logs where it seems to be processed in sequence.

For background: I'm using this for communication with embedded devices, which generally take a lot longer for their communication due to the communication protocols (e.g. 2G) used. The full handshake can easily take five seconds, so the ability to process multiple at the same time would be very helpful in keeping the response times down.

@jdbruijn jdbruijn added the question Further information is requested label Aug 17, 2020
@jkralik
Copy link
Member

jkralik commented Aug 26, 2020

GoPool is used only to process COAP requests in parallel. It doesn't used for DTLS handshake.
example:

ld, _ := coapNet.NewDTLSListener("udp4", "", dtlsCfg)
p, _ := ants.NewPool(10000)
sd := dtls.NewServer(dtls.WithGoPool(p.Submit)) 
sd.Serve(ld)

@jdbruijn
Copy link
Collaborator Author

Thanks for the example. I've learned after creating this that it indeed doesn't work for the DTLS handshake.

Is it correct that the CoAP DTLS server already uses goroutines to handle CoAP requests in there, so by default already handles CoAP requests concurrently? I'm thinking that because of the default for the go pool is the following function https://github.com/plgd-dev/go-coap/blob/v2.0.4/dtls/server.go#L52-L57.
So the pool, for example with ants can be used to get more control over the pool, limit the number of goroutines etc., right?

	goPool: func(f func()) error {
		go func() {
			f()
		}()
		return nil
	},

@jkralik
Copy link
Member

jkralik commented Aug 27, 2020

Is it correct that the CoAP DTLS server already uses goroutines to handle CoAP requests in there, so by default already handles CoAP requests concurrently?

In coap protocol order of request is not guaranteed (dtls/udp). So yes I want to process request's concurrently by default. (I didn't used ants by default because I don't want to add dependency to go-coap).

So the pool, for example with ants can be used to get more control over the pool, limit the number of goroutines etc., right?

Precisly.

@jdbruijn
Copy link
Collaborator Author

I totally understand. Thanks for elaborating on this topic @jkralik !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants