Python threads and memory usage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    Python threads and memory usage

    Hi,

    I'm writing client-server application in Python. It's monitoring
    system, where server listen and waits for TCP connections, and every
    connection takes own thread. Every thread puts data from clients to
    Queue and exits. Then there is one DB loader thread, which loads all
    data from Queue to MySQL DB.

    I observed, that every thread reserved some memory, and after exit
    thread doesn't freed it. When i leaved my server working for 3 days,
    then it takes 15% of 512MB memory (during that time about 15000
    threads were created and stopped). When server starts it only takes
    about 1% of memory.

    I know that I can made client which connects once and keep this
    session with server thread all time (it should resolve my problems),
    but I'm curious if this is normal or it is something like memory leak.
    Or maybe I'm doing something wrong :)

    If You need I can paste all my code.

    Regards
  • Mike

    #2
    Re: Python threads and memory usage

    On May 30, 9:16 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
    On Thu, 29 May 2008 12:01:30 -0700 (PDT), Mike <mszpad...@gmai l.com>
    declaimed the following in comp.lang.pytho n:
    >
    I observed, that every thread reserved some memory, and after exit
    thread doesn't freed it. When i leaved my server working for 3 days,
    then it takes 15% of 512MB memory (during that time about 15000
    threads were created and stopped). When server starts it only takes
    about 1% of memory.
    >
            Do you have any outstanding references to the threads? If so, have
    you performed a .join() with the thread? Until you join it, the thread
    state (thread local objects/"variables" ) are probably being held for
    access from outside the thread.
    --
            Wulfraed        Dennis Lee Bieber               KD6MOG
            wlfr...@ix.netc om.com             wulfr...@bestia ria.com
                    HTTP://wlfraed.home.netcom.com/
            (Bestiaria Support Staff:               web-a...@bestiaria. com)
                    HTTP://www.bestiaria.com/
    I'm joining threads only during my program exit. I'll try to do what
    You suggest.

    THX

    Comment

    • Mike

      #3
      Re: Python threads and memory usage

      On May 30, 9:42 am, Mike <mszpad...@gmai l.comwrote:
      On May 30, 9:16 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
      >
      >
      >
      On Thu, 29 May 2008 12:01:30 -0700 (PDT), Mike <mszpad...@gmai l.com>
      declaimed the following in comp.lang.pytho n:
      >
      I observed, that every thread reserved some memory, and after exit
      thread doesn't freed it. When i leaved my server working for 3 days,
      then it takes 15% of 512MB memory (during that time about 15000
      threads were created and stopped). When server starts it only takes
      about 1% of memory.
      >
              Do you have any outstanding references to the threads? If so, have
      you performed a .join() with the thread? Until you join it, the thread
      state (thread local objects/"variables" ) are probably being held for
      access from outside the thread.
      --
              Wulfraed        Dennis Lee Bieber               KD6MOG
              wlfr...@ix.netc om.com             wulfr...@bestia ria.com
                      HTTP://wlfraed.home.netcom.com/
              (Bestiaria Support Staff:               web-a...@bestiaria. com)
                      HTTP://www.bestiaria.com/
      >
      I'm joining threads only during my program exit. I'll try to do what
      You suggest.
      >
      THX
      It helped. Now all threads are added to thread list and every some
      period of time I'm checking which threads are alive (enumerate), and
      joining all which aren't. Now [memory usage is still on 1% :D:D:D

      Thanks

      Comment

      Working...