Results 1 to 5 of 5

Thread: Freeze doesn't release TLS index on Freeze::SharedDbEnv::~SharedDbEnv

  1. #1
    allro is offline Registered User
    Name: Alex Leiderman
    Organization: Cell2Bet
    Project: Management Server
    Join Date
    Jul 2008
    Posts
    10

    Freeze doesn't release TLS index on Freeze::SharedDbEnv::~SharedDbEnv

    Hi,

    It looks like a bug in SharedDbEnv class - please confirm:
    allocated by constructor (_tsdKey = TlsAlloc();),
    TLS index is not released by TlsFree on destructor.

    Result: A simple loop like
    Code:
    for (int j=0; j<2000; ++j) {
       ConnectionPtr connection = createConnection(communicator(), "db");
    }
    will give us
    SharedDbEnv.cpp:440: IceUtil::ThreadSyscallException:
    syscall exception: Not enough storage is available to process this command.
    If thread local storage is used for application needs it may lead to hardly reproducible bugs.
    Possible workaround: Connection pool created on application startup - please confirm.

    Environment:
    ICE: 3.3.1 - according to source code, will happen on 3.4.1 as well
    Compiler: VS2008
    OS: Vista

    Thanks in advance,
    Best Regards,
    --Alex

  2. #2
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Alex,

    Thank you for the bug report. It looks like the SharedDbEnv destructor should indeed call TlsFree on this key.

    A good work-around is to avoid creating and destroying "shared db env" all the time, e.g. the following code would create just one SharedDbEnv:

    Code:
    ConnectionPtr cachedConnection = createConnection(communicator(), "db");
    for (int j=0; j<2000; ++j) {
       ConnectionPtr connection = createConnection(communicator(), "db");
    }
    It's also better for performance.

    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  3. #3
    allro is offline Registered User
    Name: Alex Leiderman
    Organization: Cell2Bet
    Project: Management Server
    Join Date
    Jul 2008
    Posts
    10
    Hi Bernard,

    Regarding workaround - I have some DBLayer class that looks like following:
    Code:
    class DBLayer
    {
    public ... f1(...){
        ConnectionPtr connection = createConnection(communicator(), "db");
        //Do something
    }
    public ... f2(...){
        ConnectionPtr connection = createConnection(communicator(), "db");
        //Do something
    }
    
    ...
    
    public ... fN(...){
        ConnectionPtr connection = createConnection(communicator(), "db");
        //Do something
    }
    }
    All DBLayer functions may be executed in context of multiple threads => using 1 cached connection means serialization of access to it. So, according to Ice Manual -
    If your application requires concurrent access to the same database file (persistent map), you must create several connections and associated maps.
    - it looks like I have to use a pool of connections.

    Am I correct?
    Best Regards,
    --Alex

  4. #4
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Alex,

    Creating a connection in each function is a good idea, and will allow you to use the same underlying Berkeley DB environment concurrently.

    What is missing from your code is one "cached connection", to keep the underlying Berkeley DB env opened. This is much better for performance and is also a work-around for this missing TlsFree.

    E.g.

    Code:
    class DBLayer
    {
    public:
         DBLayer()
         {
              // Ensures the underlying Berkeley DB environment remains opened
              //
              _cachedConnection = createConnection(communicator(), "db");
         }
    
          ... f1(...)
        {
              // Create a connection for the calling thread. This is very cheap
              // because the underlying Berkeley DB env is already open (thanks to
              // _cachedConnection)
              //
              ConnectionPtr connection = createConnection(communicator(), "db");
              // Do something 
         }
     
    private:
          Freeze::ConnectionPtr _cachedConnection;
    };
    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  5. #5
    allro is offline Registered User
    Name: Alex Leiderman
    Organization: Cell2Bet
    Project: Management Server
    Join Date
    Jul 2008
    Posts
    10
    Bernard,

    Thanks a lot for the clarification.
    Best Regards,
    --Alex

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Freeze and C#
    By TheRhinoDude in forum Help Center
    Replies: 7
    Last Post: 03-30-2010, 04:27 PM
  2. ways to get the max&min value of a Freeze map index?
    By peterlspot in forum Help Center
    Replies: 1
    Last Post: 01-08-2008, 07:14 AM
  3. Freeze::ConnectionPtr from Freeze::Map Obj
    By paolo in forum Comments
    Replies: 1
    Last Post: 01-05-2008, 05:02 PM
  4. Freeze in C#
    By pankajmk in forum Help Center
    Replies: 3
    Last Post: 11-20-2006, 08:55 AM
  5. About freeze
    By lixiang in forum Help Center
    Replies: 5
    Last Post: 05-28-2004, 09:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •