On Mon, Jul 8, 2019 at 9:30 AM B Carr <
buc...@gmail.com> wrote:
>
> Gophers -
>
> Trying to learn Go (I'm a hobbyist) and have a fundamental net/http question. I have a web server running with a web page set to refresh every 2 seconds. I have 3 different browsers making webserver GET requests. Each browser's refresh is spinning up a new goroutine on the server, right? And that leaves the preceding goroutine started by that browser's GET dead/unused going forward, right?
Each HTTP request is handled in its own goroutine. Once the request is
handled, that goroutine terminates. So if your HTTP handler eventually
returns, that goroutine will eventually terminate. They won't be left
"unused".
>
> I'm watching the memory usage of the webserver and it is steadily increasing though it does seem to level off after a while.
>
> Is the GC taking care of removing the unused goroutines and that is why I'm seeing the memory use increases start to level off? If I stop all the browsers would the GC gobble up all the now-useless goroutines and memory use for the webserver would drop back to nominal? At one point when I was tracking down one race condition (out of 839 reported), the race output showed "goroutine #29316". Good grief! I fixed all the race conditions reported.
The GC will cleanup the resources used by the goroutine once it
terminates, so what you're seeing is probably the transient response
of the system before it reaches a steady state.
>
> If I set the page refreshes to a larger number, such as 5 minutes, would the GC gobble up the unused goroutines fast enough that I wouldn't see much increase in memory use?
GC is fast enough, but the total number of concurrent requests you can
handle depends on how you handle your GET requests.
>
> Or am I thinking about this all wrong?
>
> TIA,
>
> Bucky
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/d2903306-e0b0-4e7e-a035-ff14b3c64c52%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.