Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bd7ee7e5
authored
Dec 02, 2025
by
Calcium-Ion
Committed by
GitHub
Dec 02, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2351 from prnake/fix-max-conns
fix: try resolve the high concurrency issue to a single host
parents
2073a907
bf1a31df
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
0 deletions
+21
-0
common/constants.go
+3
-0
common/init.go
+2
-0
relay/helper/stream_scanner.go
+2
-0
service/http_client.go
+14
-0
No files found.
common/constants.go
View file @
bd7ee7e5
...
@@ -121,6 +121,9 @@ var BatchUpdateInterval int
...
@@ -121,6 +121,9 @@ var BatchUpdateInterval int
var
RelayTimeout
int
// unit is second
var
RelayTimeout
int
// unit is second
var
RelayMaxIdleConns
int
var
RelayMaxIdleConnsPerHost
int
var
GeminiSafetySetting
string
var
GeminiSafetySetting
string
// https://docs.cohere.com/docs/safety-modes Type; NONE/CONTEXTUAL/STRICT
// https://docs.cohere.com/docs/safety-modes Type; NONE/CONTEXTUAL/STRICT
...
...
common/init.go
View file @
bd7ee7e5
...
@@ -90,6 +90,8 @@ func InitEnv() {
...
@@ -90,6 +90,8 @@ func InitEnv() {
SyncFrequency
=
GetEnvOrDefault
(
"SYNC_FREQUENCY"
,
60
)
SyncFrequency
=
GetEnvOrDefault
(
"SYNC_FREQUENCY"
,
60
)
BatchUpdateInterval
=
GetEnvOrDefault
(
"BATCH_UPDATE_INTERVAL"
,
5
)
BatchUpdateInterval
=
GetEnvOrDefault
(
"BATCH_UPDATE_INTERVAL"
,
5
)
RelayTimeout
=
GetEnvOrDefault
(
"RELAY_TIMEOUT"
,
0
)
RelayTimeout
=
GetEnvOrDefault
(
"RELAY_TIMEOUT"
,
0
)
RelayMaxIdleConns
=
GetEnvOrDefault
(
"RELAY_MAX_IDLE_CONNS"
,
500
)
RelayMaxIdleConnsPerHost
=
GetEnvOrDefault
(
"RELAY_MAX_IDLE_CONNS_PER_HOST"
,
100
)
// Initialize string variables with GetEnvOrDefaultString
// Initialize string variables with GetEnvOrDefaultString
GeminiSafetySetting
=
GetEnvOrDefaultString
(
"GEMINI_SAFETY_SETTING"
,
"BLOCK_NONE"
)
GeminiSafetySetting
=
GetEnvOrDefaultString
(
"GEMINI_SAFETY_SETTING"
,
"BLOCK_NONE"
)
...
...
relay/helper/stream_scanner.go
View file @
bd7ee7e5
...
@@ -72,6 +72,8 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
...
@@ -72,6 +72,8 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
if
common
.
DebugEnabled
{
if
common
.
DebugEnabled
{
// print timeout and ping interval for debugging
// print timeout and ping interval for debugging
println
(
"relay timeout seconds:"
,
common
.
RelayTimeout
)
println
(
"relay timeout seconds:"
,
common
.
RelayTimeout
)
println
(
"relay max idle conns:"
,
common
.
RelayMaxIdleConns
)
println
(
"relay max idle conns per host:"
,
common
.
RelayMaxIdleConnsPerHost
)
println
(
"streaming timeout seconds:"
,
int64
(
streamingTimeout
.
Seconds
()))
println
(
"streaming timeout seconds:"
,
int64
(
streamingTimeout
.
Seconds
()))
println
(
"ping interval seconds:"
,
int64
(
pingInterval
.
Seconds
()))
println
(
"ping interval seconds:"
,
int64
(
pingInterval
.
Seconds
()))
}
}
...
...
service/http_client.go
View file @
bd7ee7e5
...
@@ -34,12 +34,20 @@ func checkRedirect(req *http.Request, via []*http.Request) error {
...
@@ -34,12 +34,20 @@ func checkRedirect(req *http.Request, via []*http.Request) error {
}
}
func
InitHttpClient
()
{
func
InitHttpClient
()
{
transport
:=
&
http
.
Transport
{
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
ForceAttemptHTTP2
:
true
,
}
if
common
.
RelayTimeout
==
0
{
if
common
.
RelayTimeout
==
0
{
httpClient
=
&
http
.
Client
{
httpClient
=
&
http
.
Client
{
Transport
:
transport
,
CheckRedirect
:
checkRedirect
,
CheckRedirect
:
checkRedirect
,
}
}
}
else
{
}
else
{
httpClient
=
&
http
.
Client
{
httpClient
=
&
http
.
Client
{
Transport
:
transport
,
Timeout
:
time
.
Duration
(
common
.
RelayTimeout
)
*
time
.
Second
,
Timeout
:
time
.
Duration
(
common
.
RelayTimeout
)
*
time
.
Second
,
CheckRedirect
:
checkRedirect
,
CheckRedirect
:
checkRedirect
,
}
}
...
@@ -84,6 +92,9 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
...
@@ -84,6 +92,9 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
case
"http"
,
"https"
:
case
"http"
,
"https"
:
client
:=
&
http
.
Client
{
client
:=
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
Transport
:
&
http
.
Transport
{
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
ForceAttemptHTTP2
:
true
,
Proxy
:
http
.
ProxyURL
(
parsedURL
),
Proxy
:
http
.
ProxyURL
(
parsedURL
),
},
},
CheckRedirect
:
checkRedirect
,
CheckRedirect
:
checkRedirect
,
...
@@ -116,6 +127,9 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
...
@@ -116,6 +127,9 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
client
:=
&
http
.
Client
{
client
:=
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
Transport
:
&
http
.
Transport
{
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
ForceAttemptHTTP2
:
true
,
DialContext
:
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
DialContext
:
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
dialer
.
Dial
(
network
,
addr
)
return
dialer
.
Dial
(
network
,
addr
)
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment