c# - Thread management when populating a cache in a .NET web app -


i have .net mvc web app data reporting. when app first loads, requests lot of data remote servers caches locally in web server memory. before cache loads, there's no way respond incoming requests. every request comes in while cache loading must wait thread loading cache.

  1. if use critical section (lock) on caching code, requests block. that's huge waste of resources , exhaust iis worker thread pool.
  2. if use async requests, web requests return before cache loaded. can't "callback" web request has returned contents client!

how can manage threads properly? maybe there way move requests single thread asynchronously waits cache load , move them out individual threads once cache loaded?

if use critical section (lock) on caching code, requests block.

that true. can use semaphoreslim.waitasync asynchronously wait. behaves lock. want solution case many requests queue (like 1000s). can use second semaphore max count of 1000 , wait timeout of zero. if wait fails know >= 1000 requests running , can fail request.

big downside requests have async component it. maybe can in central place such async mvc action filter. otherwise forced make mvc actions async headache.

be sure correctly configure asp.net , iis queues.

if use async requests

not sure understand async means in context of asp.net. async request processing implementation detail of server. client can't detect it. request not prematurely completed. async io (and other form of async blocking) not cause request end prematurely.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -