I need to create a web API search function for all users on my system. The client (using the phone) sends me requests using the endpoint:
HTTP 1.1 GET http://sf.cluster:80/ Path /search/users?q=Aa&take=10
Where q is the string entered by the user in the search field. accept - how many entries the phone wants to show.
I uploaded 89,000 items from the Azure storage table to my trusted dictionary. It has the structure:
IReliableDictionary<Guid, string>
My search method is as follows:
public async Task<IEnumerable<UserInfo>> Search(string q, int take) { var usersDictionary = await GetUsersDictionary(); IEnumerable<UserInfo> results; using (var tx = StateManager.CreateTransaction()) { var searchResults = (from r in (await usersDictionary.CreateEnumerableAsync(tx)).ToEnumerable() where r.Value.StartsWith(q, StringComparison.InvariantCultureIgnoreCase) select new UserInfo() { Id = r.Key, Name = r.Value }).Take(take); results = new List<UserInfo>(searchResults); await tx.CommitAsync(); } return results; }
Problem: This works well on the phone, I got what I expected. But when I started pushing my endpoint with a bunch of requests (about ~ 60 threads at a time using the Soap UI tool ), the timeout started to grow from 1s to 35s! It seems like I was mistaken somewhere or chose the wrong implementation method.
If someone implemented some features? Can someone help with a proper search?
UPD: A stateless service is implemented where I store a List<string> with names and do the same (search through a list). Results: 150-300 ms. It looks like I should keep List in state (in the state service) and get it on request.
source share