NER1808
NER1808

Reputation: 1969

Universal Membership Provider create user performance issues

To my regret I am using the latest Universal Providers for membership management in my Azure hosted, MVC 3, SQL Azure backed development. I have coded up a routine to create users in bulk from a CSV file. The file is parsed and a model populated. I then iterate through the collection creating users.

The key line that takes an incredible amount of time is the standard

Membership.CreateUser(
   model.UserName, 
   model.Password, 
   model.Email, 
   null, 
   null, 
   model.IsApproved,
   out createStatus);

Even on a 'Large' 4 core server, this one line can take almost 1 second to complete. That means 10,000 users would take nearly 3 hours. To do it direct to the database, if I could, would probably take a few minutes.

Even worse is I also need to check for existing users and update them if they do. I have put in the necessary indexes, and the database is very fast. Frankly, what can this provider be doing?

Am I doing something wrong, or is this provider just completely useless for large scale systems? Has anyone else had these issues?

I won't even go into the Profile provider, suffice to say I have written my own!

Upvotes: 0

Views: 802

Answers (1)

Ming Xu - MSFT
Ming Xu - MSFT

Reputation: 2116

While I did not use that provider before, but the key is to create multiple users simultaneously. 1 second per user is reasonable. Moreover, Most time is spent in waiting for the database to return. When the current thread is waiting for the database to return, I would like to suggest you to create a new thread to start creating another user. So instead of creating the users one by one in a normal foreach loop, please use Parallel.ForEach, which will automatically create the users in parallel, you can refer to http://msdn.microsoft.com/en-us/library/dd460720.aspx for a sample.

Best Regards,

Ming Xu.

Upvotes: 2

Related Questions