faas-flow icon indicating copy to clipboard operation
faas-flow copied to clipboard

Use global persistence connection to enhance performance

Open s8sg opened this issue 4 years ago • 0 comments

All call to function and for next node execution are submitted via Gateway. In the current code

  • A http client was being created for each incoming message in the handler. this is a overkill, cause for every new request there will be a Handshake.
  • The http client created was using default transport. default http client does have a keep-alive setting.

We can reuse a connection instead of creating new one. We can do so by creating a global client as:

var client *http.Client

func init() {
    tr := &http.Transport{
           MaxIdleConnsPerHost: 1024,
     }
   client = &http.Client{Transport: tr }
}

When we are using common client, we also need to make sure that we

  • Read until Response is complete (i.e. ioutil.ReadAll(rep.Body))
  • Call Body.Close()

s8sg avatar Jul 28 '19 02:07 s8sg