Add configurable timeout for queries.

This commit is contained in:
2023-10-24 10:40:17 +01:00
parent 8fc5782d29
commit 3d70018179
4 changed files with 8 additions and 5 deletions
+1
View File
@@ -122,6 +122,7 @@ In this case, both proxy and websockets will be available under the `/v1/graphql
| `ENABLE_API` | Enable the monitoring API | `false` | | `ENABLE_API` | Enable the monitoring API | `false` |
| `API_PORT` | The port to expose the monitoring API | `9090` | | `API_PORT` | The port to expose the monitoring API | `9090` |
| `BANNED_USERS_FILE` | The path to the file with banned users | `/go/src/app/banned_users.json` | | `BANNED_USERS_FILE` | The path to the file with banned users | `/go/src/app/banned_users.json` |
| `PROXIED_CLIENT_TIMEOUT` | The timeout for the proxied client in seconds | `120` |
### Speed ### Speed
+2 -1
View File
@@ -50,7 +50,8 @@ func parseConfig() {
} }
return strings.Split(urls, ",") return strings.Split(urls, ",")
}() }()
c.Client.FastProxyClient = createFasthttpClient() c.Client.ClientTimeout = envutil.GetInt("PROXIED_CLIENT_TIMEOUT", 120)
c.Client.FastProxyClient = createFasthttpClient(c.Client.ClientTimeout)
c.Server.EnableApi = envutil.GetBool("ENABLE_API", false) c.Server.EnableApi = envutil.GetBool("ENABLE_API", false)
c.Server.ApiPort = envutil.GetInt("API_PORT", 9090) c.Server.ApiPort = envutil.GetInt("API_PORT", 9090)
c.Api.BannedUsersFile = envutil.Getenv("BANNED_USERS_FILE", "/go/src/app/banned_users.json") c.Api.BannedUsersFile = envutil.Getenv("BANNED_USERS_FILE", "/go/src/app/banned_users.json")
+4 -4
View File
@@ -11,7 +11,7 @@ import (
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
func createFasthttpClient() *fasthttp.Client { func createFasthttpClient(timeout int) *fasthttp.Client {
return &fasthttp.Client{ return &fasthttp.Client{
Name: "graphql_proxy", Name: "graphql_proxy",
NoDefaultUserAgentHeader: true, NoDefaultUserAgentHeader: true,
@@ -19,9 +19,9 @@ func createFasthttpClient() *fasthttp.Client {
InsecureSkipVerify: true, InsecureSkipVerify: true,
}, },
MaxConnsPerHost: 100, MaxConnsPerHost: 100,
MaxIdleConnDuration: 2 * time.Minute, MaxIdleConnDuration: time.Duration(timeout*5) * time.Minute,
ReadTimeout: time.Second * 10, ReadTimeout: time.Second * time.Duration(timeout),
WriteTimeout: time.Second * 10, WriteTimeout: time.Second * time.Duration(timeout),
DisableHeaderNamesNormalizing: true, DisableHeaderNamesNormalizing: true,
} }
} }
+1
View File
@@ -34,6 +34,7 @@ type config struct {
GQLClient *graphql.BaseClient GQLClient *graphql.BaseClient
FastProxyClient *fasthttp.Client FastProxyClient *fasthttp.Client
proxy string proxy string
ClientTimeout int
} }
Cache struct { Cache struct {