Reputation: 2815
I am using windows azure table storage. My problem is that the access of entities for a given user from table is taking long time. The code which i am using to access the table is as follows :
public CloudTableQuery<T> GetEntites(string username)
{
try
{
CloudTableQuery<T> entries =
(from e in ServiceContext.CreateQuery<T>(TableName)
where e.PartitionKey == username
select e).AsTableServiceQuery();
return entries;
}
catch (Exception)
{ return null; }
}
The total entities in the table are currently only 100 or so. For example : The query seems to take as long as 40 seconds to return 25 entities for a given user. Please suggest if there is any scope for improvement in the code for faster performance ?
Upvotes: 1
Views: 711
Reputation: 12174
The real problem here is you are returning queries instead of entities, and you are likely executing a query again for each returned entity (query). Define your entity with something like:
public class UserEntity
{
public string UserName { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Then define your table storage entity with something like:
public class StoredUserEntity : TableServiceEntity
{
public StoredUserEntity (string username)
{
this.PartitionKey = username;
this.RowKey = Guid.NewGuid().ToString();
this.Timestamp = DateTime.Now;
}
public string Email { get; set; }
public string Name { get; set; }
}
Then your query should actually return a list of UserEntities:
public List<UserEntity> GetUserData(string username)
{
var q = _tableContext.CreateQuery<StoredUserEntity>(_tableName);
return
q.ToList().Select(x => new UserEntity {UserName = x.PartitionKey, Email = x.Email, Name = x.Name}).Where(x => x.UserName == username).ToList();
}
Upvotes: 1
Reputation: 5194
Try using Fiddler to see what's going on. It could be that you are experiencing a few retries that could slow things down. The API won't tell you that, but with Fiddler you can see exactly the requests being made, any responses (along with errors) and how many of them are being made.
Upvotes: 0