mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-12 00:45:31 +00:00
General library improvements.
This commit is contained in:
@@ -11,19 +11,22 @@ import (
|
||||
)
|
||||
|
||||
func (b *BaseClient) createHttpClient() (http_client *http.Client) {
|
||||
// Optimized connection pool settings for better performance
|
||||
httpTransport := &http.Transport{
|
||||
MaxIdleConns: 512,
|
||||
MaxConnsPerHost: 512,
|
||||
MaxIdleConnsPerHost: 512,
|
||||
IdleConnTimeout: 15 * time.Second,
|
||||
ResponseHeaderTimeout: 15 * time.Second,
|
||||
MaxIdleConns: 100, // Reduced from 512
|
||||
MaxConnsPerHost: 50, // Reduced from 512
|
||||
MaxIdleConnsPerHost: 10, // Reduced from 512
|
||||
IdleConnTimeout: 30 * time.Second, // Increased for better reuse
|
||||
ResponseHeaderTimeout: 10 * time.Second, // Reduced for faster timeouts
|
||||
DisableKeepAlives: false,
|
||||
DisableCompression: false,
|
||||
WriteBufferSize: 4096, // Optimize buffer size
|
||||
ReadBufferSize: 4096, // Optimize buffer size
|
||||
}
|
||||
|
||||
if strings.HasPrefix(b.endpoint, "http://") {
|
||||
http_client = &http.Client{
|
||||
Timeout: 15 * time.Second,
|
||||
Timeout: 30 * time.Second, // Increased for better reliability
|
||||
Transport: httpTransport,
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
@@ -39,12 +42,14 @@ func (b *BaseClient) createHttpClient() (http_client *http.Client) {
|
||||
tlsClientConfig.InsecureSkipVerify = true
|
||||
}
|
||||
http2Transport := &http2.Transport{
|
||||
AllowHTTP: true,
|
||||
TLSClientConfig: tlsClientConfig,
|
||||
ReadIdleTimeout: 15 * time.Second,
|
||||
PingTimeout: 15 * time.Second,
|
||||
AllowHTTP: true,
|
||||
TLSClientConfig: tlsClientConfig,
|
||||
ReadIdleTimeout: 30 * time.Second, // Increased for better reuse
|
||||
PingTimeout: 10 * time.Second, // Reduced for faster detection
|
||||
WriteByteTimeout: 10 * time.Second, // Add write timeout
|
||||
}
|
||||
http_client = &http.Client{
|
||||
Timeout: 30 * time.Second, // Increased for better reliability
|
||||
Transport: http2Transport,
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
|
||||
Reference in New Issue
Block a user