#net/http server
19 messages · Page 1 of 1 (latest)
you must NOT run it in goroutines.
net/http will perform some cleanup when you return from the Handle function
so you would have a data race between net/http and your goroutine
*more precisely you can use goroutines but if you do you need to use sync.WaitGroup or some other synchronisation mechanism to return from Handle only after you are finished
yes net/http spawn one goroutine per invocation already
ye then i dont require to add goroutines anymore
only for in the body of the handle function but it will sync
?
when user a enters /hello and user b enters /hello at the same time, net/http pushes 2 seperate goroutines for the handler, in the handler like for example to do some database lookup i can sync goroutines it doesnt block any other client
did i understand it correct?
yes that is correct
oke thnx
your database internally maintain locks, but theses are ideally around very small sections of code
so the blocking is really small
usally writing is worst than reading (as-in, it blocks more).
go has implemented net/http Server concept pretty well its very easy to customize and make your own framework
like two readers is usually exactly as fast as one reader (assuming you have two cores).
However a reader plus a writer is slower.