Closed gbrayut closed 7 years ago
I don't know if this is relevant but have you considered sync.Once
?
Thanks for the link! In this case I don't think we need to worry about thread safety or sync/locks as the creation of the default instance can be managed in the init function.
Finished with the first draft of SWbemServices worker. I left in a bunch of print statements to show the code execution path. @captncraig Ready for a code review tomorrow AM (I'll be out tomorrow afternoon) or on Monday.
C:\Code\Go\src\github.com\stackexchange\wmi [gbray]> go test -run TestWbemQuery
InitializeSWbemServices: Starting
process: starting background thread initialization
process: initialized. closing initError
process: waiting for queries
InitializeSWbemServices: Finished
Query: Sending query request
process: new query: len(query)=773
queryBackground: Starting
queryBackground: Finished
process: s.queryBackground finished
Query: Finished
Query: Sending query request
process: new query: len(query)=775
queryBackground: Starting
queryBackground: Finished
process: s.queryBackground finished
Query: Finished
Close: sending close request
process: queries channel closed
closeBackground: Starting
closeBackground: Finished
Close: finished
PASS
ok github.com/stackexchange/wmi 0.642s
@captncraig I made the requested changes and added a benchmark. Looks like for a simple query like Win32_OperatingSystem the new method takes ~53ms and the old method takes ~63ms.
C:\Code\Go\src\github.com\stackexchange\wmi [gbray +0 ~2 -0]> go test -run=NONE -bench=Version -benchtime=120s
BenchmarkNewVersion-8 3000 53435903 ns/op
BenchmarkOldVersion-8 3000 63050507 ns/op
PASS
ok github.com/stackexchange/wmi 360.940s
Haven't found any issues while testing in Scollector, so merged these to master
I am starting to refactor the WMI/OLE initialization code out of the hot path. I talked with Craig and the current approach is going to be using a channel to send incoming query requests to a dedicated go routine that re-uses the same SWbemServices object instead of creating a new one each time. This should prevent the memory leaks we have seen on Server 2016/Windows 10 and give a good performance boost.
Goals:
go test -run TestWbemMemory -timeout 60m
)Work Items:
Unknowns: