I am evaluating NCache for usage in the ongoing project as a "read-through" cache - in order to take off load from SQL server.
At client-side, the project has a polling routine that receives items filtered (at server-side) by last polling datetime.
The polling occurs at fixed interval at separate thread.
The pseudo code for client-side
1) first time fetch:
- fetch all existing items
- set LastHandledDate to now
2) non-first time fetch (polling thread)
- fetch existing items that were created after LastHandledDate
- update LastHandledDate to now
At server-side,when the polling query is received, the following pseudo-code is executed:
- query NCache for all matching items with CreationDate >= LastHandledDate
- IF query results are empty
- query SQL database for all matching items with CreationDate >= LastHandledDate
- if query is not empty then update NCache with SQL query results
- return SQL query results
- ELSE return NCache query result
To query NCache I am using it's linq provider, and the query is similar to SQL query:
SELECT * FROM Messages WHERE Message.SessionId = 1234 AND Message.EntryDate >= ‘2012-10-6’
Edit: During testing,on the client-side there is a thread that adds new items at a constant rate
The server-side part is hosted in a web-service (WCF in IIS).
After load testing the above polling setup with 100 clients for about an hour, I've noticed a steady decline in requests/sec the web-service was performing.
Running the above setup with only reads from NCache, without SQL reads at all (without paragraph 2 at server-side pseudo-code) yielded the same decline pattern in requests/sec.
I have several questions:
- It seems that NCache's query performance depends on total number of objects in the cache. Is this the case in similar solutions (NoSQL / Distributed Cache)
- Which NoSQL/Distributed Cache solution is optimized for querying speed?
- Maybe in the NCache the querying can be somehow more optimized?
- Perhaps I am missing something- and my usage pattern of distributed cache is incorrect - how can I use distributed cache such as NCache efficiently in my use case?