performance - ASP.NET MVC and EF Code First Memory Usage -


i have application built in asp.net mvc 3 uses sql ce storage , ef ctp 5 data access.

i've deployed site shared host find being recycled it's hitting 100mb limit set on (dedicated) application pools.

the site, when running in release mode uses around 110mb ram.

i've tried using sql server express rather ce , made little difference.

the significant difference when removed ef (using fake repo). dropped memory usage between 30mb-40mb. blank mvc template uses around 20mb figured isn't bad?

are there benchmarks "standard" asp.net mvc applications?

it know memory utilisation other ef ctp users getting suggestions memory profiling tools (preferably free ones).

it's worth mentioning how i'm handling lifetime of ef objectcontext. using session per request , instantiating objectcontext using structuremap:

for<idbcontext>().httpcontextscoped().use(ctx => new mycontext("myconnstringname")); 

many ben

we did manage reduce our memory footprint quite significantly. iis worker process sits around 50mb compared 100+mb before.

below of things helped us:

  • check basics. make sure compile in release mode , set compilation debug false in web.config. it's easy forget such things.
  • use debug symbols diagnostic code. example of when using tools nhprof (yes i've been caught out before). easiest thing wrap such code in #if debug directive ensure it's not compiled release of application.
  • don't forget sql. orms make easy ignore how application talking database. using sql profiler or tools efprof/nhprof can show going on. in case of ef feel little ill afterwards, if make significant use of lazy loading. once you've got on this, can begin optimize (see point below).
  • lazy loading convenient shouldn't used in mvc views (imo). 1 of root causes of our high memory usage. home page of our web site creating 59 individual queries due lazy loading (select n+1). after creating specific viewmodel page , eagerly loading associations needed got down 6 queries executed in half time.
  • design patterns there guide you, not rule development of application. tend follow ddd approach possible. in case didn't want expose foreign keys on domain model. since ef not handle many-to-one associations quite nh (it issue query foreign key of object have in memory), ended additional query (per object) displayed on page. in case decided put bit of code smell (including fk in model) sake of improved performance.
  • a common "solution" throw caching @ performance issues. it's important identify real problem before formulate caching strategy. have applied output caching our home page (see note below) doesn't change fact have 59 queries hitting database when cache expires.

a note on output caching: when asp.net mvc first released able donut caching, is, caching page apart specific region(s). fact no longer possible makes output caching pretty useless if have user specific information on page. example, have login status within navigation menu of site. alone means can't use output caching page cache login status.

ultimately there no hard , fast rule on how optimize application. biggest improvement in our application's performance came when stopped using orm building our associations (for public facing part of our site) , instead loaded them manually our viewmodels. couldn't use ef eagerly load them there many associations (resulting in messy union query).

an example our tagging mechanism. entities blogpost , project can tagged. tags , tagable entities have many-to-many relationship. in our case better retrieve tags , cache them. created linq projection cache association keys our tagable entities (e.g. projectid / tagid). when creating viewmodel our page build tags each tagable entity without hitting database. again, specific our application yielded massive improvement in performance , in lowering our memory usage.

some of resources / tools used along way:

whilst did make improvements take under hosting company's (arvixe) application pool limits, feel sense of duty advise people looking @ windows reseller plans, such restrictions in place (since arvixe not mention anywhere when advertising plan). when looks true (unlimited x,y,z), is.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -