-
Notifications
You must be signed in to change notification settings - Fork 71
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
space leaks on executeMany #39
Comments
Well, the space leak does need to be investigated and fixed, but you can make your original code run much faster by running it in a single transaction instead of one transaction per insert as you are now. postSaveCandles :: Connection -> [Candle] -> IO ()
postSaveCandles c cndls = withTransaction c $ do
mapM_ (execute c "insert into candles (open, close, minc, maxc, volume, timec, periodtype, periodsecs) values (?,?,?,?,?,?,?,?)") cndls
return () |
But i actually do dbMakeCandles count = do
con <- connect $ ConnectInfo "127.0.0.1" 5432 "test" "test" "test"
cndls <- genCandles
withTransaction con $ postSaveCandles con $ take count $ map (\x -> x `deepseq` x) cndls I will try to write more tests to narrow this problem. |
Ok, what do you mean by a "space leak"? Have you tried running the heap profiler on your program? Unfortunately, Haskell's memory consumption is not, in general, a local property. How much space a function uses is not only a question of how the function is written, but also how the result is consumed. Just be aware of that issue when trying to isolate this issue. |
Yes. I am not sure i understand what i got in the profiling, i am not very familiar with heap profiling in Haskell, but there is truangular peak while program runs. It generates huge amount of some data, then folding it down.
Ok |
Out of curiosity, have you tried compiling postgresql-simple with heap profiling enabled? This may not actually be a space leak, though it's entirely possible that What I would suggest is writing a test program that exhibits the issue. I see that you are using |
I have written some tests https://github.com/s9gf4ult/teststorage here two executables GenerateTest and PostTest. First generate given amount of objects and dies, second does "executeMany" on given amount of Storagles and then select is back. Both executables take one parameter with amount of storables to operate on, default is 10000 if parameter is skipped. To work PostTest you need "test" as user, password and database name on localhost, or change it manually on line 14 of PostTest.hs Memory consumed 5 times more on inserts then on selects. I think this is because of Haskell does not release intermediate data memory until completely execute database query. This is posible not a space leak but some king of ... what ? |
I accidentally closed this issue .. |
By the way, did you ever get this resolved? The link to your code is no longer available... |
Oh, I was looking at the link in your original post; thanks for the test cases! |
Ok, I did take a brief look at your test case; the one thing that stands out to me is that your insert appears to take quadratic time: doubling the number of elements in the test case approximately quadruples the amount time it takes to make the insert. And I did verify that the problem is inside postgresql-simple itself. It only appears to be a problem when strings need to be escaped via libpq... my first attempt to replicate this outside of your test case was not successful because I only used integers which do not get escaped via libpq. In any case, here's a stripped down test case that exhibits the behavior:
I then compiled this file and then timed it using the unix |
Bug #39 is definitely worthy of being added to CONTRIBUTORS
Ok, I fixed postgresql-libpq's binding to |
Hello.
I am trying to use postgresql-simple to store many same data in the database.
When my function looks like this
My program leaks. I mean it constructs very many Candle consuming memory and then reduces them and executes query.
When i do this
It works smothsly, inserts each candle one by one, but not very fast. I think bacause of many exec's.
Candle looks like this
And have instance ToRow
Candle generates just random with this instance
which is quite lazy.
here is all code
https://github.com/s9gf4ult/hadan/blob/master/post.hs
The text was updated successfully, but these errors were encountered: