Coder Social home page Coder Social logo

How do I recycle cursors? about momoko HOT 11 CLOSED

fsx avatar fsx commented on June 5, 2024
How do I recycle cursors?

from momoko.

Comments (11)

FSX avatar FSX commented on June 5, 2024

The PoolError says that you're out of connections, which means you've gone over the limit of 1000. db.batch requires a connection for each query (more or less).

I don't really know where the InterfaceError: cursor already closed comes from. Cursors shouldn't be closed. And there is not really a way to reuse cursors, because it would involve manually setting the connection state and callbacks. So that's why the cursor is hidden away in the connection class ans is inly used for fetching data after a query has been done.

from momoko.

swasheck avatar swasheck commented on June 5, 2024

Right, but once the big batch is done my connection pool should drop, right? Postgres shows that these connections are gone so when I start a new batch I should be starting from scratch, right? Like i said, this is probably me doing something wrong.

On Sep 29, 2012, at 2:43 AM, Frank Smit [email protected] wrot

The PoolError says that you're out of connections, which means you've gone over the limit of 1000. db.batch requires a connection for each query (more or less).

I don't really know where the InterfaceError: cursor already closed comes from. Cursors shouldn't be closed. And there is not really a way to reuse cursors, because it would involve manually setting the connection state and callbacks. So that's why the cursor is hidden away in the connection class ans is inly used for fetching data after a query has been done.


Reply to this email directly or view it on GitHub.

from momoko.

FSX avatar FSX commented on June 5, 2024

It should. Your code looks correct to me, so the only thing I can think of is that too much connections are needed or something goes wrong inside of Momoko. Can you give me more information about he amount of queries and data? I can make a test case and see if I can reproduce it.

from momoko.

tesh11 avatar tesh11 commented on June 5, 2024

I came across an issue with cursors on the rewrite branch. In the busy() getter on Connection, the parentheses are missing on the call to isexecuting. That keeps the connections from being cleaned up.

from momoko.

FSX avatar FSX commented on June 5, 2024

I saw your pull request and merged it.

from momoko.

tesh11 avatar tesh11 commented on June 5, 2024

Thanks!

On Wed, Oct 10, 2012 at 3:57 AM, Frank Smit [email protected]:

I saw your pull request and merged it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/34#issuecomment-9294375.

from momoko.

arielakeman avatar arielakeman commented on June 5, 2024

I'm getting the same issue on 1.0.0b2 when the database is hit hard, particularly with a yield to an array of moko.Op's. The queries are heavy, it's a local (internal) application and can take between half a second and five seconds to execute.

The relevant parts of the stack trace are

File "D:...\momoko-1.0.0b2-py3.2.egg\momoko\connection.py", line 287, in io_callback
self.callback(None)

results[i].fetchall()
psycopg2.InterfaceError: cursor already closed

from momoko.

FSX avatar FSX commented on June 5, 2024

Ok, I think I might have an idea of what is going wrong. The connection might be closed before the results are fetched from the cursor. I'm not completely sure, but after running a small test I get the same error.

I'm at work/internship at the moment so I can't dive into right now. I have time later tonight.

from momoko.

arielakeman avatar arielakeman commented on June 5, 2024

Thanks, much appreciated.

from momoko.

FSX avatar FSX commented on June 5, 2024

I'm stuck. What I think is happing is that the connection is closed by the connection pool cleaner while the cursor is still being used.It seemed easy to fix by keeping a set of weak references to the cursors in the Connection class. When the set is empty (it becomes empty when the cursors are deleted by the garbage collector) the connection can be closed again. But I can't get it to work. I'm trying to figure out why. I also wasn't able to find anything in Psycopg2's connection class that idicates that there are still opened cursors. That would have made it a lot easier. Maybe I'm also overthinking it.

You could try disabling the pool cleaner by setting cleanup_timeout to 0 and setting the minimum amount of connections to a appropriate amount for now.

I'm going to FOSDEM tomorrow so I don't much time, but I'll try to come up with something while I'm on the train!

from momoko.

FSX avatar FSX commented on June 5, 2024

@arielakeman, @swasheck. I've written about a possible solution in #41.

from momoko.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.