When and how to go about performing caching in asp.net mvc? - asp.net-mvc-2

UPDATE : I also found ncache which seems useful and also came to know that stackoverflow uses redis for caching. I also have come across memcached and seems one of the better alternatives.
I have found this but I needed to know what are the ways in which I can cache some of my LINQ queries and use them efficiently. I found Output cache in asp.net mvc are there other ways to do caching?
I am kind of a newbie and never done caching before so I would appreciate if anyone can point me in the right direction here? Mainly I want answer to when would be caching necessary and how to go about doing caching in asp.net mvc ?

In my experience application level caching is rarely the correct approach to fixing performance issues and it nearly always causes more problems than it solves.
Before you embark on any caching you should first:
(i) profile your application and the queries it makes to see if you can address them directly (e.g. query patterns that are too wide (fetching columns that aren't displayed) or too deep (e.g. fetching more rows than you display), too frequent (lazy loading might be causing more round trips than you need), too expensive (poor table design might mean more joins than you need), or the tables themselves might not be indexed correctly;
(ii) take a holistic look at your web site and the user experience to see how you can improve the perceived performance (e.g. set proper browser-level cache cache headers on static content). Using AJAX might and a paged grid view like jQGrid might eliminate many database accesses while a user is paging through records because the rest of the page content is not changing.
After you've exhausted fixing the real problem you may then then be ready to consider caching.
But before you do, make a simple calculation: how much does an upgraded server cost vs the development and testing time you will spend implementing caching and tracking down odd stale-cache issues? Sometimes it's cheaper just to upgrade...

Related

Design factors that need to considered for application with very high Transactions Per Second (TPS)

I am about to work on an application that need to handle high transactions per second (around 5000). The application needs to provide REST interface, with server side technologies including EJB, JMS, Infinispan.
Could you please let me know briefly the best practices that need to be considered while designing the application that needs to handle high volume of requests. Also please point to some resources which give more information.
Some of the factors that comes to mind are
1. Asynchronous processing (Servlet 3.0) support for REST
2. Stateless, as suggested by JB Nizet
3. Optimizing Data access(Second level hibernate cache, Cache read only data, proper column indexing)
4. Queuing long running tasks (JMS)
A lot of it is going to come down to specifics, as #JBNizet said.
How much hardware can you throw at the problem? Again, per #JBNizet, a stateless API scales really nicely in a cluster. Enough hardware can solve any performance problem - it becomes a cost tradeoff between solving performance in hardware vs. software.
Can you design your resources so they are cache friendly? Anything you can cache will save you a boatload.
Can you set up a reverse-proxy server like Squid to keep cached calls out of your data access layer?
Absolutely look at configuring your L2 cache and optimizing your database access layer. You'll want to do some reading on caching in a cluster .. there are different ways to keep your clustered caches in sync.
At a certain point, this becomes a a performance testing problem, too. Automate a suite of test calls to the API, hook up JVisualVM, and see where your bottlenecks are. Keep an eye on Hibernate, in particular. You may be better off in some cases with using custom SQL, especially if there are large differences between your data layer and your API layer.

Need advice modelling a large application with EXTJS 4.2

I am currently working with a Banking firm, we have a requirement to develop a fairly complex but Rich UI application. We are using EXTJS 4.2 and Spring MVC.
The first release of the app went into Production about a month back.
Now while modelling the new phase, we have come across a major hurdle. The application load up time is fairly high at this point of time. This is happening because the application has followed a single Page web 2.0 model and multiple JS files which when minified -> all-classes.js is 3 MB.
Now there is a lot of work to be done going ahead in order to build additional functionality.
Since all code is getting loaded at once during startup it would take a lot of time for this.
I figured out a design but I am not sure if that would help.. If we divide our application into multiple pages each have a different --> all-classes.js , will it help improve the performance ?
I need some advice on this.
You can refer to this links which I found : http://docs.sencha.com/extjs/4.2.0/#!/guide/command_app_multi
http://www.sencha.com/forum/showthread.php?130449-Large-Single-Page-Architecture-in-ExtJS-4.0/page2
Well, there are a number of answers to this, the best of which is "it depends".
Splitting into multiple pages is obviously going to produce some performance improvements. After all, you'll (presumably) have smaller files to initially load, fewer controllers to instantiate, etc.
The question is how much? I'm not sure I can answer that very well, without knowing more about the app and how it's structured.
I do know this, however. I have an app whose all-classes.js is around 2 MB. While there is obviously the initial hit loading it, subsequent visits use a cached version of it. And even the initial load of the 2MB file is pretty fast on most decent connections.

Azure Hadoop and Entity Framework

I am stating a new project that needs to be portable and in some scenarios will have 100's millions of entities.
Now with Azure getting hadoop that of course got my attention for the big data scenario. But I also have the small data scenario under 1 million rows.
Entity Framework code-first is they way I see designing this but needing hadoop in the mix of course may complicate things (Entity Framework of course been used to give simpler storage providers for the smaller data sets)
Now the question is does anyone have experience in this mix?
Can anyone recommended if this is a good approach or not, if not is there a better way?
Working on a reasonably large system based on Entity Framework Code First, with the caveats that I have been working with EF4 and cannot upgrade to 5, that your mileage may vary and the outcomes are going to be strongly affected by what you intend to do, my experience has been that EF doesn't handle large amounts of data tremendously well, it is quite inflexible, so if you need to change its standard behaviour in some way there is a good chance you are going to end up having to hack some nasty workarounds, and performance isn't amazing. If you want to do things that aren't exactly the things that EF expects you to do, then you can run into walls.
If I was thinking of designing a relatively simple/small scale Asp.Net MVC setup, I think EF is a really good choice. For a larger scale operation where you need more flexibility or you are planning to go beyond basic operations you might find that something like NHibernate works better. I don't have experience with that, but colleagues who have worked with both tend to prefer NHibernate. ( Brief article on the comparison - a bit old so EF has addressed some, but not all of the points there. It is also different by design of course. )
It may be that for more high-traffic or unusual stuff you need to roll your own data access anyway just to achieve the right performance or be able to find the right data. Unsquestionably, if you are planning to try working with EF I strongly recommend some serious prototyping just to ensure it can do what you need.

multithread database fetch xcode

Hi thank you for the help in advance,
I have looked at some of the posts and I am a bit confused about the multi threading. It seems that it may be pretty easy, however I am very new to programming so I am still trying to grasp this.
These are two calls to pull data from a database, and they take forever as it is... So I'm thinking about multithreading these until I can learn how to build a core data for this. Right now i am using sqllite and the database involves 10,000 + recipes... So not lightning fast like I would like...
Please let me know what you think, and how I can make these happen maybe simultaneously? (If thats even possible)
Thank you in advance.
requestCount++;
[[DataPuller sharedDataPuller] getAllDeletedRecipeList];
[DataPuller sharedDataPuller].target = self;
requestCount++;
[[DataPuller sharedDataPuller] getAllRecipesList];
[DataPuller sharedDataPuller].target = self;
If you're doing SQLite, you might want to contemplate using FMDB which (a) gets you out of the weeds of sqlite3 calls; and (b) offers a FMDatabaseQueue which allows you to coordinate queries from multiple queues, so that the data operations don't stumble across each other.
Having said that, you suggest that you're having significant performance issues which you're hoping to solve with a shift to Core Data or going multi-threaded with SQLite. That's unlikely. Poor performance of local database operations is generally more of a matter of your application design (e.g. it's unlikely to be wise to try to retrieve the entire details for all 10,000 recipes ... you probably want to retrieve just the unique identifiers, perhaps only those required for the given screen, and then only retrieve the particulars for a given recipe at a later point as you need that). For local database interaction, you rarely have to contemplate a multithreaded implementation, but rather just design the system to retrieve the least possible information at any given point that you need for the presentation. I personally find that my database-driven apps generally only need to go multithreaded when I'm doing extensive interaction with some remote web service (in which case, it's the retrieval of server data and the parsing of that which goes on the separate thread, not necessarily the database operations themselves).
If you're having performance issues with your recipe app, I'd suggest you submit a far more detailed question, with code samples, that articulates your particular performance problem. And I wouldn't be surprised if multi-threading was not part of the solution. Likely, appropriate use of indexes and a more judicious retrieval of information at any given point might be more critical.
Get records from database in the form of pages; i.e. 20 or 50 recipes per page. Have a look on YouTube app. on iPhone or have a look on my app. HCCHelper

Caching solutions for multi-webserver configuration?

I am looking into caching solutions, for a multi webserver configuration. Thought of memcached as being cheap (free) and proven over the years. Microsoft is also developing a caching solution for webfarms, called Velocity, but this is still in CTP2.
There is a distributed caching model used in the configuration service that is part of the .NET Stocktrader sample application. This is a framework that allows you to run multiple nodes with centralised configuration management, load balancing and distributed caching. You can implement the configuration service as is or look through the code and grab what suits you. Worth a look.
When I listened to Scott Hanselman's podcast interview with the StackOverflow team, I was left with the impressions that a. they did use some kind of caching and b. they knew almost nothing about what they were doing in this respect and had fiddled with a few options and then written a blog post or two.
They currently seem to use client-side caching rather half-heartedly (short expiry times on images, for example), and I think they use a lot of ASP.NET user-mode caching, and I can't tell if they use IIS kernel-mode caching. (They didn't seem to be able to tell Scott that, either.)
However, the podcast was a while back, and I was driving at the time, so my memory might be wrong and/or out of date.
You should think HARD before bringing in something like memcached.
Caching can hide performance issues from you ("got a slow running query? just cache it and dont worry about fixing it!")
Invalidating stale data out is a nightmare.
You may spend days chasing bugs that get cleared up when you clear the cache, and it pollutes your code base.
I'm not saying don't do it, but think HARD before you do.
If you can get enough performance by adding a couple* of extra machines (which I think stackoverflow can) then do that and don't worry about caching. It'll be much cheaper in the long run.
*note I don't say 100 machines.