-3

I was testing things out and noticed that when I made Google API calls, my program would create 2 extra goroutines (went from 1 to 3 goroutines). I feel like this would lead to a problem where too many goroutines are created.

developer
  • 45
  • 5
  • 3
    Anything can create goroutines. What is "too many goroutines"? – JimB Aug 03 '18 at 21:41
  • 2
    Come back when you have a few million goroutines and a load average of 1.0. :) – Michael Hampton Aug 03 '18 at 21:49
  • When our stack space will be filled due to having a bunch of goroutines – developer Aug 03 '18 at 21:51
  • Goroutines are not OS threads. You can have many goroutines on a single thread. Each requires only a few bytes of state. See also [How do goroutines work? (or: goroutines and OS threads relation)](https://stackoverflow.com/q/24599645/1068283) – Michael Hampton Aug 03 '18 at 21:53
  • 1
    @developer: The stack limit in go is 1,000,000,000 bytes. It takes a lot of goroutines to hit that, and usually only caused by runaway recursion. – JimB Aug 03 '18 at 22:07

1 Answers1

2

Do API calls create goroutines?

Not inherently. But many implementations of APIs of course will.

I was testing things ... my program would create 2 extra goroutines.

Why do you think this is "extra"? It's probably exactly the right number of goroutines.

I feel like this would lead to a problem where too many goroutines are created.

Don't. You are wrong to feel this way. There's absolutely nothing wrong with using goroutines--that's why they exist.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189