New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leakage #316
Comments
Hi, driver has no memory leak. Driver uses buffer pool for the each connect. You can have some problem, if you didn't set max conn and max idle conn. Also check your driver settings https://github.com/ClickHouse/clickhouse-go#dsn |
Hi, @Akado2009 @kshvakov . I suppose the issue here is that in the first Example of the readme of this repo connect.Close() is missing. So if you copied this example to your code, connection will not be released to the pool and memory will be leaking. Just add |
@nickiv you must use sql.open only once in your app |
@kshvakov you are right, and documentation say so. I mistakenly used it many times and symptoms were just like @Akado2009 mentioned in issue (same top memory consumers NewCompressWriter and NewCompressReader). connect.Close() eliminates the leak, but still it is better to rewrite code so sql.open is used only once! Thanks! |
@nickiv Hi, I also encountered a similar problem. The heap is constantly growing. I close the connection, but the heap memory cannot be reduced. I would like to ask how to solve it. |
@jinxing3114 how many times in your code sql.open is called? If you call sql.open more then once (like in a loop or on event), than your leak could be related to this issue. Rewrite the code so it is called once, on program initialization. If not, then it must be something else. Please try to use pprof to investigate what consumes memory. |
@jinxing3114 Hi ! I suggest you check for sql.open firstly. Secondly, as for my issue - I was clearing the slice with sl = sl[:0] and then filling it again. But this doesn't actually delete elements, they still exist (at least the memory occupied by it). So by time the memory usage of this slice went from 1kb to 2gb. Good luck! |
@nickiv sql.open is executed only once. The results I checked through pprof are almost the same, both NewCompressWriter and NewCompressReader occupies most of the memory, and the number of heaps continues to increase. My code is similar to #360 (comment). After initialization, it will continue to perform write queries and other operations, and only see the heap growth. conn, err = sql.Open("clickhouse", "tcp://127.0.0.1:9000?debug=false")
if err != nil {
return err
}
conn.SetMaxOpenConns(5)
conn.SetMaxIdleConns(1)
conn.SetConnMaxLifetime(time.Minute) |
Hi @jinxing3114 any update on this? |
Can't reproduce in V2 stress.go |
Hi,
so I have a program that reads data from kafka nad pushes it to clickhouse. So here is a function establishing a connection.
Here is a function to insert the data.
so there is a problem of memory leakage.
Here is a heap inuse memory from pprof
And it keeps growing, any ideas on fixing?
The text was updated successfully, but these errors were encountered: