8

I have a RESTful API in Golang that my Angular website calls.

Does the Go http module by default handle requests in sequence or concurrently?

Also, if my HandlerFunc in Go calls a python script, would concurrent calls to this HandlerFunc spawn multiple python processes, or would they be blocked till one is complete?

Nishant Roy
  • 1,043
  • 4
  • 16
  • 35
  • 1
    Concurrent. Possible duplicate of [Webhook process run on another goroutine](https://stackoverflow.com/questions/37782073/webhook-process-run-on-another-goroutine/37783535#37783535); and [Server instances with multiple users](https://stackoverflow.com/questions/44070323/server-instances-with-multiple-users/44070394#44070394); and [Process Management for the Go Webserver](https://stackoverflow.com/questions/37529511/process-management-for-the-go-webserver/37531953#37531953). – icza Jul 10 '17 at 06:17
  • Gotcha! And how about calling the python script? Will the concurrent goroutines be blocked? – Nishant Roy Jul 10 '17 at 07:38
  • 1
    I don't know how you call them and what they do, but in general you could say that the calling goroutine (request) will be blocked, but you can call the script from multiple requests, concurrently. – icza Jul 10 '17 at 07:40
  • `exec.Command("python", pythonFile, args)` is how I call it – Nishant Roy Jul 10 '17 at 09:02
  • I would suggest you test it by adding code in python that sleeps for several seconds. – WiredPrairie Jul 10 '17 at 10:35
  • 1
    @WiredPrairie That's just the way you create an `exec.Cmd`. `Cmd.Run()` runs it and waits for it to complete (blocks). `Cmd.Start()` starts it but does not wait (does not block). If you use `Cmd.Start()`, you may use `Cmd.Wait()` to wait for it to complete. – icza Jul 10 '17 at 12:49
  • @icza -- I understand that -- I'm suggesting that a little bit of testing could resolve these questions easily. – WiredPrairie Jul 10 '17 at 14:04
  • @WiredPrairie Actually I meant to address that comment to the asker NishantRoy... – icza Jul 10 '17 at 14:06
  • @icza - :) gotcha – WiredPrairie Jul 10 '17 at 16:05

1 Answers1

4

Yes, by default all http requests can be executed concurrently.

If you are executing a python script, then indeed a separate process will be spawned and they will execute concurrently.

Please note that this carries the potential risk of spawning too many processes and running out of resources.

Kalyan02
  • 1,416
  • 11
  • 16