github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/transport/tinit.go (about) 1 // Package transport provides long-lived http/tcp connections for 2 // intra-cluster communications (see README for details and usage example). 3 /* 4 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 5 */ 6 package transport 7 8 import ( 9 "container/heap" 10 "os" 11 "strconv" 12 "time" 13 14 "github.com/NVIDIA/aistore/cmn" 15 "github.com/NVIDIA/aistore/cmn/cos" 16 "github.com/NVIDIA/aistore/cmn/nlog" 17 "github.com/NVIDIA/aistore/memsys" 18 ) 19 20 // transport defaults 21 const ( 22 dfltBurstNum = 128 // burst size (see: config.Transport.Burst) 23 dfltTick = time.Second 24 dfltTickIdle = dfltTick << 8 // (when there are no streams to _collect_) 25 dfltIdleTeardown = 4 * time.Second // (see config.Transport.IdleTeardown) 26 ) 27 28 type global struct { 29 tstats cos.StatsUpdater // subset of stats.Tracker interface, the minimum required 30 mm *memsys.MMSA 31 } 32 33 var ( 34 g global 35 dfltMaxHdr int64 // memsys.PageSize or cluster-configurable (`config.Transport.MaxHeaderSize`) 36 verbose bool 37 ) 38 39 func Init(tstats cos.StatsUpdater, config *cmn.Config) *StreamCollector { 40 verbose = cmn.Rom.FastV(5 /*super-verbose*/, cos.SmoduleTransport) 41 42 g.mm = memsys.PageMM() 43 g.tstats = tstats 44 45 nextSessionID.Store(100) 46 for i := range numHmaps { 47 hmaps[i] = make(hmap, 4) 48 } 49 50 dfltMaxHdr = dfltSizeHeader 51 if config.Transport.MaxHeaderSize > 0 { 52 dfltMaxHdr = int64(config.Transport.MaxHeaderSize) 53 } 54 // real stream collector 55 gc = &collector{ 56 ctrlCh: make(chan ctrl, 64), 57 streams: make(map[string]*streamBase, 64), 58 heap: make([]*streamBase, 0, 64), // min-heap sorted by stream.time.ticks 59 } 60 gc.stopCh.Init() 61 heap.Init(gc) 62 63 sc = &StreamCollector{} 64 return sc 65 } 66 67 func burst(extra *Extra) (burst int) { 68 if extra.WorkChBurst > 0 { 69 return extra.WorkChBurst 70 } 71 config := extra.Config 72 if burst = config.Transport.Burst; burst == 0 { 73 burst = dfltBurstNum 74 } 75 if a := os.Getenv("AIS_STREAM_BURST_NUM"); a != "" { 76 if burst64, err := strconv.ParseInt(a, 10, 0); err != nil { 77 nlog.Errorln(err) 78 } else { 79 burst = int(burst64) 80 } 81 } 82 return 83 }