Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang HTTP server requests async or sync?

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?

like image 438
Nishant Roy Avatar asked Jul 10 '17 06:07

Nishant Roy


People also ask

Is HTTP request is synchronous or asynchronous?

HTTP is a synchronous protocol: the client issues a request and waits for a response. If you are using non-blocking (aka async) IO, the current thread of the client does not really have to wait, but can do other things (see above).

Is Go HTTP server concurrent?

Go's built-in net/http package is convenient, solid and performant, making it easy to write production-grade web servers. To be performant, net/http automatically employs concurrency; while this is great for high loads, it can also lead to some gotchas.

Is Golang synchronous?

Async/Await is a language feature that provides a simpler interface to asynchronous programming. Golang is a concurrent programming language with powerful features like Goroutines and Channels.

How does async HTTP work?

The answer is: Async doesn't change the HTTP protocol. The HTTP protocol is centered around a request and a matching response. That's it. There's no progress reporting, or multiple responses per request, or anything like that.


1 Answers

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.

like image 129
Kalyan02 Avatar answered Oct 29 '22 04:10

Kalyan02