mirror of https://github.com/ehang-io/nps
change some bandwidth calculation
parent
9bb8230fc1
commit
405f41f87f
|
@ -10,7 +10,7 @@ const PoolSizeSmall = 100
|
||||||
const PoolSizeUdp = 1472
|
const PoolSizeUdp = 1472
|
||||||
const PoolSizeCopy = 32 << 10
|
const PoolSizeCopy = 32 << 10
|
||||||
const PoolSizeBuffer = 4096
|
const PoolSizeBuffer = 4096
|
||||||
const PoolSizeWindow = PoolSizeBuffer - 16 - 32 - 32 - 8
|
const PoolSizeWindow = PoolSizeBuffer - 2 - 4 - 4 - 1
|
||||||
|
|
||||||
var BufPool = sync.Pool{
|
var BufPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
|
|
|
@ -190,7 +190,7 @@ func (Self *ReceiveWindow) New(mux *Mux) {
|
||||||
// initial a window for receive
|
// initial a window for receive
|
||||||
Self.bufQueue.New()
|
Self.bufQueue.New()
|
||||||
Self.element = common.ListElementPool.Get()
|
Self.element = common.ListElementPool.Get()
|
||||||
Self.maxSize = 4096
|
Self.maxSize = common.MAXIMUM_SEGMENT_SIZE
|
||||||
Self.mux = mux
|
Self.mux = mux
|
||||||
Self.window.New()
|
Self.window.New()
|
||||||
}
|
}
|
||||||
|
@ -209,21 +209,25 @@ func (Self *ReceiveWindow) calcSize() {
|
||||||
// calculating maximum receive window size
|
// calculating maximum receive window size
|
||||||
if Self.count == 0 {
|
if Self.count == 0 {
|
||||||
//logs.Warn("ping, bw", Self.mux.latency, Self.bw.Get())
|
//logs.Warn("ping, bw", Self.mux.latency, Self.bw.Get())
|
||||||
n := uint32(2 * math.Float64frombits(atomic.LoadUint64(&Self.mux.latency)) *
|
conns := Self.mux.connMap.Size()
|
||||||
Self.mux.bw.Get() / float64(Self.mux.connMap.Size()))
|
n := uint32(math.Float64frombits(atomic.LoadUint64(&Self.mux.latency)) *
|
||||||
if n < 8192 {
|
Self.mux.bw.Get() / float64(conns))
|
||||||
n = 8192
|
if n < common.MAXIMUM_SEGMENT_SIZE*2 {
|
||||||
|
n = common.MAXIMUM_SEGMENT_SIZE * 2
|
||||||
}
|
}
|
||||||
bufLen := Self.bufQueue.Len()
|
bufLen := Self.bufQueue.Len()
|
||||||
if n < bufLen {
|
if n < bufLen {
|
||||||
n = bufLen
|
n = bufLen
|
||||||
}
|
}
|
||||||
|
if n < Self.maxSize/2 {
|
||||||
|
n = Self.maxSize / 2
|
||||||
|
}
|
||||||
// set the minimal size
|
// set the minimal size
|
||||||
if n > 2*Self.maxSize {
|
if n > 2*Self.maxSize {
|
||||||
n = 2 * Self.maxSize
|
n = 2 * Self.maxSize
|
||||||
}
|
}
|
||||||
if n > common.MAXIMUM_WINDOW_SIZE {
|
if n > (common.MAXIMUM_WINDOW_SIZE / uint32(conns)) {
|
||||||
n = common.MAXIMUM_WINDOW_SIZE
|
n = common.MAXIMUM_WINDOW_SIZE / uint32(conns)
|
||||||
}
|
}
|
||||||
// set the maximum size
|
// set the maximum size
|
||||||
//logs.Warn("n", n)
|
//logs.Warn("n", n)
|
||||||
|
@ -377,8 +381,8 @@ type SendWindow struct {
|
||||||
|
|
||||||
func (Self *SendWindow) New(mux *Mux) {
|
func (Self *SendWindow) New(mux *Mux) {
|
||||||
Self.setSizeCh = make(chan struct{})
|
Self.setSizeCh = make(chan struct{})
|
||||||
Self.maxSize = 4096
|
Self.maxSize = common.MAXIMUM_SEGMENT_SIZE
|
||||||
atomic.AddUint64(&Self.remainingWait, uint64(4096)<<dequeueBits)
|
atomic.AddUint64(&Self.remainingWait, uint64(common.MAXIMUM_SEGMENT_SIZE)<<dequeueBits)
|
||||||
Self.mux = mux
|
Self.mux = mux
|
||||||
Self.window.New()
|
Self.window.New()
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,34 +115,35 @@ func (s *Mux) writeSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Mux) packBuf() {
|
func (s *Mux) packBuf() {
|
||||||
buffer := common.BuffPool.Get()
|
//buffer := common.BuffPool.Get()
|
||||||
for {
|
for {
|
||||||
if s.IsClose {
|
if s.IsClose {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
buffer.Reset()
|
//buffer.Reset()
|
||||||
pack := s.writeQueue.Pop()
|
pack := s.writeQueue.Pop()
|
||||||
if s.IsClose {
|
if s.IsClose {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
//buffer := common.BuffPool.Get()
|
//buffer := common.BuffPool.Get()
|
||||||
err := pack.Pack(buffer)
|
err := pack.Pack(s.conn)
|
||||||
common.MuxPack.Put(pack)
|
common.MuxPack.Put(pack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("mux: pack err", err)
|
logs.Error("mux: pack err", err)
|
||||||
common.BuffPool.Put(buffer)
|
//common.BuffPool.Put(buffer)
|
||||||
|
s.Close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
//logs.Warn(buffer.String())
|
//logs.Warn(buffer.String())
|
||||||
//s.bufQueue.Push(buffer)
|
//s.bufQueue.Push(buffer)
|
||||||
l := buffer.Len()
|
//l := buffer.Len()
|
||||||
n, err := buffer.WriteTo(s.conn)
|
//n, err := buffer.WriteTo(s.conn)
|
||||||
//common.BuffPool.Put(buffer)
|
//common.BuffPool.Put(buffer)
|
||||||
if err != nil || int(n) != l {
|
//if err != nil || int(n) != l {
|
||||||
logs.Error("mux: close from write session fail ", err, n, l)
|
// logs.Error("mux: close from write session fail ", err, n, l)
|
||||||
s.Close()
|
// s.Close()
|
||||||
break
|
// break
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,24 +386,24 @@ func (s *Mux) getId() (id int32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type bandwidth struct {
|
type bandwidth struct {
|
||||||
|
readBandwidth uint64 // store in bits, but it's float64
|
||||||
readStart time.Time
|
readStart time.Time
|
||||||
lastReadStart time.Time
|
lastReadStart time.Time
|
||||||
bufLength uint16
|
bufLength uint32
|
||||||
readBandwidth uint64 // store in bits, but it's float64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Self *bandwidth) StartRead() {
|
func (Self *bandwidth) StartRead() {
|
||||||
if Self.readStart.IsZero() {
|
if Self.readStart.IsZero() {
|
||||||
Self.readStart = time.Now()
|
Self.readStart = time.Now()
|
||||||
}
|
}
|
||||||
if Self.bufLength >= 16384 {
|
if Self.bufLength >= 3072000 {
|
||||||
Self.lastReadStart, Self.readStart = Self.readStart, time.Now()
|
Self.lastReadStart, Self.readStart = Self.readStart, time.Now()
|
||||||
Self.calcBandWidth()
|
Self.calcBandWidth()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Self *bandwidth) SetCopySize(n uint16) {
|
func (Self *bandwidth) SetCopySize(n uint16) {
|
||||||
Self.bufLength += n
|
Self.bufLength += uint32(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Self *bandwidth) calcBandWidth() {
|
func (Self *bandwidth) calcBandWidth() {
|
||||||
|
@ -417,6 +418,7 @@ func (Self *bandwidth) Get() (bw float64) {
|
||||||
if bw <= 0 {
|
if bw <= 0 {
|
||||||
bw = 100
|
bw = 100
|
||||||
}
|
}
|
||||||
|
//logs.Warn(bw)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue