1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

reduce concurrency

This commit is contained in:
Darien Raymond 2018-11-24 23:10:04 +01:00
parent 4ff26a36ad
commit 5ecec6afd8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 25 additions and 20 deletions

View File

@ -39,7 +39,6 @@ func removeInactiveSessions(sessions []*sessionContext) []*sessionContext {
activeSessions = append(activeSessions, s)
} else {
s.rawConn.Close()
s.session.Close()
}
}
@ -52,6 +51,10 @@ func removeInactiveSessions(sessions []*sessionContext) []*sessionContext {
func openStream(sessions []*sessionContext) (quic.Stream, net.Addr) {
for _, s := range sessions {
if !isActive(s.session) {
continue
}
stream, err := s.session.OpenStream()
if err != nil {
newError("failed to create stream").Base(err).AtWarning().WriteToLog()
@ -78,18 +81,19 @@ func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsCo
sessions = s
}
sessions = removeInactiveSessions(sessions)
s.sessions[dest] = sessions
stream, local := openStream(sessions)
if stream != nil {
return &interConn{
stream: stream,
local: local,
remote: destAddr,
}, nil
{
stream, local := openStream(sessions)
if stream != nil {
return &interConn{
stream: stream,
local: local,
remote: destAddr,
}, nil
}
}
sessions = removeInactiveSessions(sessions)
rawConn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
IP: []byte{0, 0, 0, 0},
Port: 0,
@ -99,12 +103,13 @@ func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsCo
}
quicConfig := &quic.Config{
ConnectionIDLength: 12,
ConnectionIDLength: 8,
HandshakeTimeout: time.Second * 8,
IdleTimeout: time.Second * 600,
MaxReceiveStreamFlowControlWindow: 512 * 1024,
IdleTimeout: time.Second * 30,
MaxReceiveStreamFlowControlWindow: 128 * 1024,
MaxReceiveConnectionFlowControlWindow: 2 * 1024 * 1024,
MaxIncomingUniStreams: -1,
MaxIncomingStreams: 32,
}
conn, err := wrapSysConn(rawConn, config)
@ -123,7 +128,7 @@ func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsCo
session: session,
rawConn: conn,
})
stream, err = session.OpenStream()
stream, err := session.OpenStream()
if err != nil {
return nil, err
}

View File

@ -101,12 +101,12 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
}
quicConfig := &quic.Config{
ConnectionIDLength: 12,
ConnectionIDLength: 8,
HandshakeTimeout: time.Second * 8,
IdleTimeout: time.Second * 600,
MaxReceiveStreamFlowControlWindow: 512 * 1024,
MaxReceiveConnectionFlowControlWindow: 4 * 1024 * 1024,
MaxIncomingStreams: 8192,
IdleTimeout: time.Second * 30,
MaxReceiveStreamFlowControlWindow: 128 * 1024,
MaxReceiveConnectionFlowControlWindow: 2 * 1024 * 1024,
MaxIncomingStreams: 32,
MaxIncomingUniStreams: -1,
}