This project has moved. For the latest updates, please go here.

PersistentDictionary - multi processes issues

Oct 21, 2011 at 7:53 AM

Hi,

I am trying to use PersitentDictionary in an asp.net application. I make an intensive usage of the dictionary at each page request.

I have one implementation like this which works fine...

public static class Test
    {
        const string Path = "c:\\WhateverPath";
        public static string Get(string key)
        {
            string result;
            // I intentionally removed here the need for a semaphore 
            // but it is needed in cross-process access
            using (var dictionary = new PersistentDictionary<stringstring>(Path))
            {
                result = dictionary[key];
            }
            return result;
        }
    }

But  I'd like to avoid the (heavy!) cost of opening the database at each access. I'd like to go for something like this:

    // I intentionally removed the proper implementation of 
    // a disposable singleton for clarity of my request
    public static class Test2
    {
        const string Path = "c:\\WhateverPath";
        static PersistentDictionary<stringstring> dictionary;
        
        static Test2()
        {
            dictionary = new PersistentDictionary<stringstring>(Path);
        }
 
        void OnDispose()
        {
            dictionary.Flush();
            dictionary.Dispose();
        }
 
        public static string Get(string key)
        {
            return dictionary[key];
        }
    }

My issue is when .net runtime creates a new worker process my application got stucked because the esent database is already open in the first one.

Any idea on how I could turn around my issue is most welcome....

 

Many thanks,

Guirec

Oct 26, 2011 at 9:07 PM

When hosting ESENT inside asp.net it will pay off to limit your application pool to 1 worker process - since that is the biggest single requirement for read+write esent access.

You could wrap your instance in a singleton inside global.asax and use the application_start/application_end events.

Oct 27, 2011 at 6:55 AM
Thanks paalstal.
For performance reason I can't afford to limit to 1 worker process. The right trade-off might be inter process communication, I'll have a try.


From: [email removed]
To: [email removed]
Date: Wed, 26 Oct 2011 14:07:32 -0700
Subject: Re: PersistentDictionary - multi processes issues [ManagedEsent:276677]

From: paalstaal
When hosting ESENT inside asp.net it will pay off to limit your application pool to 1 worker process - since that is the biggest single requirement for read+write esent access.
You could wrap your instance in a singleton inside global.asax and use the application_start/application_end events.
Read the full discussion online.
To add a post to this discussion, reply to this email (ManagedEsent@discussions.codeplex.com)
To start a new discussion for this project, email ManagedEsent@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Oct 27, 2011 at 7:32 PM

If performance is an issue I doubt IPC will be much of help. How many requests/second are you aiming for? 500 / sec? 1500 / sec? etc..

Anyway - with ESENT your database access will always be exclusive to a single process (although by opening it read only you can have multiple processes access the same EDB file)