RuntimeTools / SwiftMetrics

Swift Application Metrics instruments the Swift runtime for performance monitoring, providing the monitoring data programatically via an API or visually with an Eclipse Client.
https://developer.ibm.com/swift/monitoring-diagnostics/application-metrics-for-swift/
Other
154 stars 49 forks source link

Memory leak when using SwiftMetrics #185

Closed svanimpe closed 6 years ago

svanimpe commented 6 years ago

When I include SwiftMetrics into my app as follows:

if let metrics = try? SwiftMetrics() {
    _ = try? SwiftMetricsDash(swiftMetricsInstance : metrics, endpoint: router)
}

my memory usage increases by about 50KB/s.

I am using SwiftMetrics 2.3 with Swift 4.1.2.

sjanuary commented 6 years ago

@svanimpe I would expect SwiftMetrics to increase memory usage over a certain period of time when it starts, but it should level off at some point. We've certainly run SwiftMetricsDash with earlier versions of Swift for multiple days at a time although I haven't done that with Swift 4.1.x yet. If you keep it running do you see the usage level out after a while?

svanimpe commented 6 years ago

I've let it run for about half an hour and memory usage was already over 100MB. Given that my app only uses about 10MB on average and is only allocated 128MB, I don't consider this normal.

sjanuary commented 6 years ago

Yes, that does seem very high. What kind of system are you running on? Is it just a simple Kitura app that you're running?

svanimpe commented 6 years ago

I am running on macOS 10.13. When I deploy the same code to Bluemix (also using Swift 4.1), the memory usage stays fixed around 10MB, even after several hours, so this seems to be Mac-specific.

I've also tried doing a release build on Mac, but that had the same issue as the debug build.

sjanuary commented 6 years ago

My sample project shows completely flat memory usage using SwiftMetrics 2.3 with Swift 4.1.2 on Linux. I'll see if I or someone else can reproduce this on a Mac.

jonathan-spruce commented 6 years ago

I have been able to reproduce the memory leak on Mac using SwiftMetrics 2.3 with Swift 4.1.2. However I am also seeing issues with the dashboard displaying multiple boxes for each metric in both Firefox and Safari:

dashboad
sjanuary commented 6 years ago

@svanimpe - we have tracked down this memory leak today and we are planning to publish a fix in the next day or two. We think the bug is in the SwiftyJSON package as it relates to converting JSON objects to Strings, but we are coding a workaround in SwiftMetrics for the sake of expediency. cc @seabaylea @tobespc @neurosaurus

sjanuary commented 6 years ago

Fixed and now published in SwiftMetrics 2.4.0