Reputation: 1235
For using Nginx with Go, the solution I see normally is using Nginx's fastcgi_pass and Go's "net/http/fcgi".
However I wonder if the use of Go's http facility is redundant here. Since Nginx would output the response as http response, can one simply pass the strings return from the Go script to Nginx and let Nginx create the http response?
Any further explanations about the underlying workflow and performance implication would be greatly appreciated.
Upvotes: 0
Views: 827
Reputation: 55453
Did you read the FactCGI spec? It explicitly defines how FastCGI server and clients pefrorm their exchange:
3.3 Records
Applications execute requests from a Web server using a simple protocol. Details of the protocol depend upon the application's role, but roughly speaking the Web server first sends parameters and other data to the application, then the application sends result data to the Web server, and finally the application sends the Web server an indication that the request is complete.
All data that flows over the transport connection is carried in FastCGI records. FastCGI records accomplish two things. First, records multiplex the transport connection between several independent FastCGI requests. This multiplexing supports applications that are able to process concurrent requests using event-driven or multi-threaded programming techniques. Second, records provide several independent data streams in each direction within a single request. This way, for instance, both stdout and stderr data can pass over a single transport connection from the application to the Web server, rather than requiring separate connections.
typedef struct { unsigned char version; unsigned char type; unsigned char requestIdB1; unsigned char requestIdB0; unsigned char contentLengthB1; unsigned char contentLengthB0; unsigned char paddingLength; unsigned char reserved; unsigned char contentData[contentLength]; unsigned char paddingData[paddingLength]; } FCGI_Record;
A FastCGI record consists of a fixed-length prefix followed by a variable number of content and padding bytes.
…
As you can see, it's a binary protocol, rather different from HTTP.
Upvotes: 1
Reputation: 10857
I've never made use of fastcgi for an actual deployment though I assisted with a functional example once. As far as performance, I'd benchmark an fcgi deployment against a reverse proxy setup and compare.
Upvotes: 1