Closed helloworldpark closed 5 years ago
@helloworldpark, thanks for taking the time to create an issue! I wonder if you can tell me what kind of memory usage you're seeing that would cause an OOM? The candles themselves should occupy at most 130 bytes, meaning you could hold almost 8000 of them in 1MB of memory.
My recommendation, if you need to cut memory usage, would be to recreate the MACDIndicator every time you need a reading from it, which would obviously reconstruct the cache.
Thanks for your advice! Think I did my math wrong. I'll just increase my cache to 10001 for the moment, then implement the logic reconstructing the cache if full.
I'm running a server which appends candles to a
techan.TimeSeries
struct. Since I can't save the candles forever(if so, Out Of Memory will make me crazy), I'm throwing away the old ones if a new candle is appended(for example, iflen(timeSeries.Candles) > 200
, I throw up the old ones to hold only 200 candles). I'll call my candles` slice MyBuffer. The problem is: if I run MACD, it gives me the same value for every new candle appended. And the reason I analysed is this: https://github.com/sdcoffey/techan/blob/018e9f93c71ae6ddf483cb7a53689db12a8d3c4e/indicator_moving_average.go#L48 Theema.resultCache
's result is returned, since the size of the cache is set to be very large and MyBuffer is much more small, therefore always passing the condition to return the cached value.Is setting MyBuffer's size the only way to solve this situation? Or is there other graceful way to this problem?