I am fighting with huge performance problems on my website. I tried nearly everything I can image, i can google or I know to solve this, but no help.
My site loads in around 700-800ms to 2.000-2.500ms. I can isolate the problem exactly on database querys - on a single site without a single query I have 110ms, for every query, as simple as it might be, i must add around 60ms to 150ms, so a simple site with: 1) Get User-Object, 2) Get all User for an online List, 3) Get a Friendlist for this user, means I allready at 300+ms. A site with more data to load, lets say 5 simple querys, needs around 800+ to load. The curios thing is, that my SQL Performance test says every query do not need 1ms itself!
What I try until now:
- Try the same database on another database-server, no performanse-increase
- Try another server for IIS, so host the page on another server, no performance-increase
- Try database on different server versions (2005, 2008 and 2012), no increase
- Be sure the load is not caused by much users (same load times on a fresh SQL Server with me as only user)
Here is a sample in my site.master, the default.aspx display nothing, so its empty, only datrabase query, this site will load in 300ms:
Guid userID = Guid.Parse(Request.Cookies["UserID"].Value);
Dal.User user = DAL.UserDAL.GetUser(userID);
List<DAL.User> onlineList = DAL.UserDAL.GetAllOnlineUser();
List<DAL.UserFriend> friendList = DAL.UserDAL.GetAllFriends(userID);
In my DAL:
public static User GetUser(Guid userID)
{
using (RPGDataContext dc = new RPGDataContext())
{
User u = (from a in dc.Users where a.UserID == userID select a).SingleOrDefault();
if (u != null && u.UserID != Guid.Empty)
{
return u;
}
else
{
return null;
}
}
}
public static List<User> GetAllOnlineUser()
{
using (RPGDataContext dc = new RPGDataContext())
{
return (from a in dc.Users where a.RefreshPing > DateTime.Now.AddMinutes(-15) orderby a.Username select a).ToList();
}
}
public static List<UserFriend> GetAllFriends(Guid userID)
{
using (RPGDataContext dc = new RPGDataContext())
{
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<UserFriend>(a => a.User);
options.LoadWith<UserFriend>(a => a.User1);
dc.LoadOptions = options;
return (from a in dc.UserFriends where a.UserIDActive == userID select a).ToList();
}
}
So basicly its very easy querys, very easy code, no place for much mistakes!
I alsy runned the DataWizard SQL Profiler on my live-website while 12 users are online, call a normal site with a few (10-12) querys which loads in around 1,5 sec, thats the result: http://abload.de/image.php?img=asdzxkdd.jpg
I don't know whats to do... the database is set up properly, PKs are Guids with PK on it, FK are all set properly, here a screen: http://abload.de/image.php?img=asdasdzqjin.jpg
Ideas I have, but nothing I can found about in the internet: - Are Guid as PK? May this be a reason the database is so slow? - maybe its a problem with the connection itself, is it okay to open a new DataContext every Query?
No more ideas... Hope someone will help here... I am a little bit helpless!
Update 1
After a few suggestions on Indexing I set the Index on UserID and RPGID, the with 95% most Coloumns which are used in Where-Clauses but not a single ms increase...