Comments (4)
// recvLoop keeps on reading from underlying connection if tokens are available
recvLoop()
for {
for atomic.LoadInt32(&s.bucket) <= 0 && !s.IsClosed() {
select {
case <-s.bucketNotify:
case <-s.die:
return
}
}
由这段代码可知,当s.bucket小于0时,将不能从tcp缓冲拿数据。
session 将不能响应 对端的任何指令。包括关闭那个已经写超时的stream。
除非从stream中读数据,腾出缓冲空间
from smux.
如果设计将指令(cmdSYN,cmdFIN,cmdNOP)与数据接收指令(cmdPSH) 分开接收,可解决关闭那个已经写超时的stream,并回收缓存空间。
但是,
经测试,如果 s.bucket 满后,不再从tcp 中读数据,又会导致tcp的缓冲区满。要拿到关闭指令任然需要将之前的数据取出。
from smux.
一个待商榷的方案,用两层buffer。
session
上一个小buffer(1024),用于tcp
拆粘包。将接收到的完成数据包分到对应的stream
。stream
上一个大buffer(65535),缓冲数据流。
write:从stream
的写wbuffer
中取最多 1024个字节。经session
编码发送到对端,对端 接收到完整包后将其投递到对应stream。若对端 stream buffer不够,响应buffer满,本端尝试重发。
read:直接从 stream 上读取数据。
什么时候尝试重发?假设在stream上设置一个标记,对端write步骤触发本端buffer满时,本端设置标记。本端read步骤时,通告对端可以继续发送了。
上面的 buffer 大小应可以自己调节,避免多次拆包。
from smux.
lgtm, 为了整体的 SLO,并且保证其它 stream 的最佳性能,应该直接放弃慢的 stream frame,并 RST 对应 Stream。
from smux.
Related Issues (20)
- 修正一处细节, HOT 4
- Blocked streams under heavy load HOT 5
- smux multiplexes multiple TCP connections?
- Stream does not return net.Error for timeouts
- alloc module memory release HOT 1
- What's the difference between version1 and version2 in smux.Config? HOT 4
- cmdFIN and cmdPSH race condition HOT 2
- 如何检测一个 Conn 是否 muxing?
- proposal: add option to not close idle session HOT 1
- 写超时,应用层选择重发 HOT 1
- 看了好多遍都没看懂,这个地方没有错误吗 HOT 15
- TestGetDieCh() strange behaviour seems cause by racing
- 建议增加一个 Session.GetCloseChan() 的函数,可以使用select快速得知连接已经被断开 HOT 6
- An extra character appears when using io.Copy
- 想问下协议版本1和2有什么区别 HOT 5
- 能否支持自动匹配客户端版本 (version 1,2) HOT 2
- Multiplexing over SCTP unordered mode HOT 2
- OpenStream似乎有并行性能问题
- 当并发newStream 较高时,recvLoop存在内存泄露 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smux.