Skip to content

Commit

Permalink
perf: use template instead of Interface{} in LockFreePool
Browse files Browse the repository at this point in the history
  • Loading branch information
lzf575 committed Nov 4, 2024
1 parent 7b88a66 commit 7c955b8
Show file tree
Hide file tree
Showing 41 changed files with 119 additions and 119 deletions.
4 changes: 2 additions & 2 deletions server/controller/trisolaris/vtap/process_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ type PidPair struct {
pid1 uint32
}

var pidPairPool = pool.NewLockFreePool(func() interface{} {
var pidPairPool = pool.NewLockFreePool(func() *PidPair {
return &PidPair{}
})

func newPidPair() *PidPair {
return pidPairPool.Get().(*PidPair)
return pidPairPool.Get()
}

func releasePidPair(pidPair *PidPair) {
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/app_log/dbwriter/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (l *ApplicationLogStore) GenerateNewFlowTags(cache *flow_tag.FlowTagCache)
}
}

var logPool = pool.NewLockFreePool(func() interface{} {
var logPool = pool.NewLockFreePool(func() *ApplicationLogStore {
return &ApplicationLogStore{
IsIPv4: true,
AttributeNames: []string{},
Expand All @@ -338,7 +338,7 @@ var logPool = pool.NewLockFreePool(func() interface{} {
})

func AcquireApplicationLogStore() *ApplicationLogStore {
e := logPool.Get().(*ApplicationLogStore)
e := logPool.Get()
e.Reset()
return e
}
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/event/dbwriter/alert_event_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
"github.com/deepflowio/deepflow/server/libs/pool"
)

var alertEventPool = pool.NewLockFreePool(func() interface{} {
var alertEventPool = pool.NewLockFreePool(func() *AlertEventStore {
return &AlertEventStore{}
})

func AcquireAlertEventStore() *AlertEventStore {
return alertEventPool.Get().(*AlertEventStore)
return alertEventPool.Get()
}

func ReleaseAlertEventStore(e *AlertEventStore) {
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/event/dbwriter/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ func (e *EventStore) GenerateNewFlowTags(cache *flow_tag.FlowTagCache) {
}
}

var eventPool = pool.NewLockFreePool(func() interface{} {
var eventPool = pool.NewLockFreePool(func() *EventStore {
return &EventStore{
AttributeNames: []string{},
AttributeValues: []string{},
}
})

func AcquireEventStore() *EventStore {
e := eventPool.Get().(*EventStore)
e := eventPool.Get()
e.Reset()
return e
}
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/exporters/prometheus_exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ func (e *PrometheusExporter) sendRequest(queueID int, batchs []prompb.TimeSeries
return nil
}

var prompbTimeSeriesPool = pool.NewLockFreePool(func() interface{} {
var prompbTimeSeriesPool = pool.NewLockFreePool(func() *prompb.TimeSeries {
return &prompb.TimeSeries{
Samples: make([]prompb.Sample, 1),
}
})

func AcquirePrompbTimeSeries() *prompb.TimeSeries {
return prompbTimeSeriesPool.Get().(*prompb.TimeSeries)
return prompbTimeSeriesPool.Get()
}

func ReleasePrompbTimeSeries(t *prompb.TimeSeries) {
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/ext_metrics/dbwriter/ext_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ func (m *ExtMetrics) GenerateNewFlowTags(cache *flow_tag.FlowTagCache) {
}
}

var extMetricsPool = pool.NewLockFreePool(func() interface{} {
var extMetricsPool = pool.NewLockFreePool(func() *ExtMetrics {
return &ExtMetrics{}
})

func AcquireExtMetrics() *ExtMetrics {
return extMetricsPool.Get().(*ExtMetrics)
return extMetricsPool.Get()
}

var emptyUniversalTag = flow_metrics.UniversalTag{}
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/flow_log/log_data/l4_flow_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,13 +1065,13 @@ func (f *L4FlowLog) HitPcapPolicy() bool {
return len(f.AclGids) > 0
}

var poolL4FlowLog = pool.NewLockFreePool(func() interface{} {
var poolL4FlowLog = pool.NewLockFreePool(func() *L4FlowLog {
l := new(L4FlowLog)
return l
})

func AcquireL4FlowLog() *L4FlowLog {
l := poolL4FlowLog.Get().(*L4FlowLog)
l := poolL4FlowLog.Get()
l.ReferenceCount.Reset()
return l
}
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/flow_log/log_data/l4_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (p *L4Packet) String() string {
return fmt.Sprintf("L4Packet: %+v\n", *p)
}

var poolL4Packet = pool.NewLockFreePool(func() interface{} {
var poolL4Packet = pool.NewLockFreePool(func() *L4Packet {
return new(L4Packet)
})

func AcquireL4Packet() *L4Packet {
l := poolL4Packet.Get().(*L4Packet)
l := poolL4Packet.Get()
return l
}

Expand Down
4 changes: 2 additions & 2 deletions server/ingester/flow_log/log_data/l7_flow_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,12 @@ func (k *KnowledgeGraph) FillL7(l *pb.AppProtoLogsBaseInfo, platformData *grpc.P
)
}

var poolL7FlowLog = pool.NewLockFreePool(func() interface{} {
var poolL7FlowLog = pool.NewLockFreePool(func() *L7FlowLog {
return new(L7FlowLog)
})

func AcquireL7FlowLog() *L7FlowLog {
l := poolL7FlowLog.Get().(*L7FlowLog)
l := poolL7FlowLog.Get()
l.ReferenceCount.Reset()
return l
}
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/flow_tag/app_service_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func (t *AppServiceTag) Release() {
ReleaseAppServiceTag(t)
}

var appServiceTagPool = pool.NewLockFreePool(func() interface{} {
var appServiceTagPool = pool.NewLockFreePool(func() *AppServiceTag {
return &AppServiceTag{}
})

func AcquireAppServiceTag() *AppServiceTag {
f := appServiceTagPool.Get().(*AppServiceTag)
f := appServiceTagPool.Get()
return f
}

Expand Down
4 changes: 2 additions & 2 deletions server/ingester/flow_tag/flow_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ func (t *FlowTag) Release() {
ReleaseFlowTag(t)
}

var flowTagPool = pool.NewLockFreePool(func() interface{} {
var flowTagPool = pool.NewLockFreePool(func() *FlowTag {
return &FlowTag{}
})

func AcquireFlowTag(tagType TagType) *FlowTag {
f := flowTagPool.Get().(*FlowTag)
f := flowTagPool.Get()
f.ReferenceCount.Reset()
f.TagType = tagType
return f
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/pcap/dbwriter/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (p *PcapStore) String() string {
return fmt.Sprintf("PcapStore: %+v\n", *p)
}

var poolPcapStore = pool.NewLockFreePool(func() interface{} {
var poolPcapStore = pool.NewLockFreePool(func() *PcapStore {
return new(PcapStore)
})

func AcquirePcapStore() *PcapStore {
l := poolPcapStore.Get().(*PcapStore)
l := poolPcapStore.Get()
return l
}

Expand Down
4 changes: 2 additions & 2 deletions server/ingester/profile/dbwriter/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (p *InProcessProfile) OrgID() uint16 {
return p.OrgId
}

var poolInProcess = pool.NewLockFreePool(func() interface{} {
var poolInProcess = pool.NewLockFreePool(func() *InProcessProfile {
return new(InProcessProfile)
})

Expand All @@ -273,7 +273,7 @@ func (p *InProcessProfile) String() string {
}

func AcquireInProcess() *InProcessProfile {
l := poolInProcess.Get().(*InProcessProfile)
l := poolInProcess.Get()
return l
}

Expand Down
8 changes: 4 additions & 4 deletions server/ingester/prometheus/dbwriter/prometheus_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,25 +284,25 @@ func (m *PrometheusSample) GenerateNewFlowTags(cache *flow_tag.FlowTagCache, met
m.PrometheusSampleMini.GenerateNewFlowTags(cache, metricName, timeSeries, extraLabels, tsLabelNameIDs, tsLabelValueIDs)
}

var prometheusSampleMiniPool = pool.NewLockFreePool(func() interface{} {
var prometheusSampleMiniPool = pool.NewLockFreePool(func() *PrometheusSampleMini {
return &PrometheusSampleMini{}
})

func AcquirePrometheusSampleMini() *PrometheusSampleMini {
return prometheusSampleMiniPool.Get().(*PrometheusSampleMini)
return prometheusSampleMiniPool.Get()
}

func ReleasePrometheusSampleMini(p *PrometheusSampleMini) {
p.AppLabelValueIDs = p.AppLabelValueIDs[:0]
prometheusSampleMiniPool.Put(p)
}

var prometheusSamplePool = pool.NewLockFreePool(func() interface{} {
var prometheusSamplePool = pool.NewLockFreePool(func() *PrometheusSample {
return &PrometheusSample{}
})

func AcquirePrometheusSample() *PrometheusSample {
return prometheusSamplePool.Get().(*PrometheusSample)
return prometheusSamplePool.Get()
}

var emptyUniversalTag = flow_metrics.UniversalTag{}
Expand Down
4 changes: 2 additions & 2 deletions server/ingester/prometheus/decoder/slow_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ type SlowItem struct {
ts prompb.TimeSeries
}

var slowItemPool = pool.NewLockFreePool(func() interface{} {
var slowItemPool = pool.NewLockFreePool(func() *SlowItem {
return &SlowItem{}
})

func AcquireSlowItem(vtapId, epcId, podClusterId, orgId, teamId uint16, ts *prompb.TimeSeries, extraLabels []prompb.Label) *SlowItem {
s := slowItemPool.Get().(*SlowItem)
s := slowItemPool.Get()
s.vtapId = vtapId
s.epcId = epcId
s.podClusterId = podClusterId
Expand Down
12 changes: 6 additions & 6 deletions server/libs/app/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func (d *DocumentFlow) String() string {
d.Timestamp, d.Flags, d.Tag, d.FlowMeter)
}

var poolDocumentFlow = pool.NewLockFreePool(func() interface{} {
var poolDocumentFlow = pool.NewLockFreePool(func() *DocumentFlow {
return &DocumentFlow{}
})

func AcquireDocumentFlow() *DocumentFlow {
d := poolDocumentFlow.Get().(*DocumentFlow)
d := poolDocumentFlow.Get()
d.ReferenceCount.Reset()
return d
}
Expand Down Expand Up @@ -157,12 +157,12 @@ func (d *DocumentApp) String() string {
d.Timestamp, d.Flags, d.Tag, d.AppMeter)
}

var poolDocumentApp = pool.NewLockFreePool(func() interface{} {
var poolDocumentApp = pool.NewLockFreePool(func() *DocumentApp {
return &DocumentApp{}
})

func AcquireDocumentApp() *DocumentApp {
d := poolDocumentApp.Get().(*DocumentApp)
d := poolDocumentApp.Get()
d.ReferenceCount.Reset()
return d
}
Expand Down Expand Up @@ -198,12 +198,12 @@ func (d *DocumentUsage) String() string {
d.Timestamp, d.Flags, d.Tag, d.UsageMeter)
}

var poolDocumentUsage = pool.NewLockFreePool(func() interface{} {
var poolDocumentUsage = pool.NewLockFreePool(func() *DocumentUsage {
return &DocumentUsage{}
})

func AcquireDocumentUsage() *DocumentUsage {
d := poolDocumentUsage.Get().(*DocumentUsage)
d := poolDocumentUsage.Get()
d.ReferenceCount.Reset()
return d
}
Expand Down
4 changes: 2 additions & 2 deletions server/libs/codec/simple_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ func (e *SimpleEncoder) String() string {
}

// pool of encoder
var simpleEncoderPool = pool.NewLockFreePool(func() interface{} {
var simpleEncoderPool = pool.NewLockFreePool(func() *SimpleEncoder {
return new(SimpleEncoder)
})

func AcquireSimpleEncoder() *SimpleEncoder {
e := simpleEncoderPool.Get().(*SimpleEncoder)
e := simpleEncoderPool.Get()
e.ReferenceCount.Reset()
return e
}
Expand Down
4 changes: 2 additions & 2 deletions server/libs/datastructure/linked_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/deepflowio/deepflow/server/libs/pool"
)

var elementPool = pool.NewLockFreePool(func() interface{} {
var elementPool = pool.NewLockFreePool(func() *Element {
return new(Element)
})

Expand All @@ -37,7 +37,7 @@ type LinkedList struct {
}

func element(v interface{}) *Element {
e := elementPool.Get().(*Element)
e := elementPool.Get()
e.value = v
return e
}
Expand Down
8 changes: 4 additions & 4 deletions server/libs/datatype/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ func FormatGroupId(id uint32) uint32 {
}
}

var endpointInfoPool = pool.NewLockFreePool(func() interface{} {
var endpointInfoPool = pool.NewLockFreePool(func() *EndpointInfo {
return new(EndpointInfo)
})

func AcquireEndpointInfo() *EndpointInfo {
return endpointInfoPool.Get().(*EndpointInfo)
return endpointInfoPool.Get()
}

func ReleaseEndpointInfo(i *EndpointInfo) {
Expand All @@ -243,12 +243,12 @@ func CloneEndpointInfo(i *EndpointInfo) *EndpointInfo {
return dup
}

var endpointDataPool = pool.NewLockFreePool(func() interface{} {
var endpointDataPool = pool.NewLockFreePool(func() *EndpointData {
return new(EndpointData)
})

func AcquireEndpointData(infos ...*EndpointInfo) *EndpointData {
d := endpointDataPool.Get().(*EndpointData)
d := endpointDataPool.Get()
len := len(infos)
if len == 0 {
d.SrcInfo = AcquireEndpointInfo()
Expand Down
4 changes: 2 additions & 2 deletions server/libs/datatype/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,12 @@ func (f *Flow) String() string {
}

var ZeroFlowPerfStats FlowPerfStats = FlowPerfStats{}
var flowPerfStatsPool = pool.NewLockFreePool(func() interface{} {
var flowPerfStatsPool = pool.NewLockFreePool(func() *FlowPerfStats {
return new(FlowPerfStats)
})

func AcquireFlowPerfStats() *FlowPerfStats {
return flowPerfStatsPool.Get().(*FlowPerfStats)
return flowPerfStatsPool.Get()
}

func ReleaseFlowPerfStats(s *FlowPerfStats) {
Expand Down
4 changes: 2 additions & 2 deletions server/libs/datatype/meta_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ func (b *MetaPacketBlock) String() string {
return result
}

var metaPacketBlockPool = pool.NewLockFreePool(func() interface{} {
var metaPacketBlockPool = pool.NewLockFreePool(func() *MetaPacketBlock {
return new(MetaPacketBlock)
}, pool.OptionPoolSizePerCPU(16), pool.OptionInitFullPoolSize(16))

func AcquireMetaPacketBlock() *MetaPacketBlock {
b := metaPacketBlockPool.Get().(*MetaPacketBlock)
b := metaPacketBlockPool.Get()
b.ReferenceCount.Reset()
return b
}
Expand Down
Loading

0 comments on commit 7c955b8

Please sign in to comment.