1
Vote

Memory leak on fim service, multithreading and load balancing

description

Dear all,

We have also been facing consistent memory leaks on fim service.

We are currently revisiting our code that calls the fim client code. After a certain point, it throws remote socket exception not accepting any further request. Has anyone faced this issue?

We have not implemented multi threading but would like to do so at the earliest. We need to implement multithreading on our code plus the fimclient code too.

In addition this we are planning for load balancing across multiple fim service instances. Please let us know how to do so.

Please provide pointers to fix this issue.

Thank you
Carol

comments

mgercevich wrote May 13, 2015 at 7:26 PM

Hi Carol,

I have implemented code to perform multi threaded requests against FIM via this project. I have not encountered any of the memory leaks you are seeing. I usually limit my parallel threads to no more than 32 per client.

One thing to note is that when you go to implement tasks executing on multiple threads, you will need to pass a reference to the Client and a reference to the Identity to impersonate. In the new thread, you must re-impersonate the Identity prior to calling the client methods. The new thread does not keep the impersonation context of the parent thread.

I am calling the following method via a Parallel ForEach :
System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
transactions.EachParallel( t => t.SubmitTransaction( client, identity);
public void SubmitTransaction(Microsoft.ResourceManagement.Client.DefaultClient Client, System.Security.Principal.WindowsIdentity identity)
{
    lock (ProcessingLatch)
    {
        // Only process this transaction onee.
        if (this.Status.Equals(String.Empty))
        {
            System.Security.Principal.WindowsImpersonationContext wi = null;
            try
            {
                wi = identity.Impersonate();
                Client.Put(this.Transaction);
                this.Status = "Submitted";
            }
            catch (FaultException<Microsoft.ResourceManagement.Client.Faults.AuthorizationRequiredFault>)
            {
                // Pending Approval.
                this.Status = "Pending Approval";
            }
            catch (Exception ex)
            {
                // Failed.
                this.Status = "Failed:" + ex.Message;
            }
            finally
            {
                if (wi != null)
                {
                    wi.Undo();
                }
            }
        }
    }
}