Although threads can help with loading a single page (assuming your server has at least 5 processor cores), this is not a scalable approach. What to do if 3 users immediately got into the application? Then you will need 15 cores on the server to improve performance.
AJAX may be a solution, but it suffers from the same scalability problem because each AJAX request will receive its own stream. On the bright side, AJAX provides preliminary speed improvements for the end user, because he can see that something is loading, even if the lagging parts of the page take the same time.
What you really need to see if, due to performance, a database appears, these are asynchronous database queries. You can run 5 asynchronous calls for 5 parts of a page and reduce load times by up to 5 times. This will make the code more complicated though. In addition, if you are trying to combine this with the AJAX approach, you need to look at asynchronous ASP.NET pages or asynchronous WCF services to avoid scalability issues when there are many users, because each user occupies 5 threads.
The code for asynchronous calls will look something like this:
Page_Load() { BeginDBRequest1(); BeginDBRequest2(); BeginDBRequest3(); BeginDBRequest4(); BeginDBRequest5(); data1 = EndDBRequest1(); data2 = EndDBRequest2(); data3 = EndDBRequest3(); data4 = EndDBRequest4(); data5 = EndDBRequest5(); //all of the above calls take the time of the max time call and not the sum of the times RenderSection1(data1); //1 sec RenderSection2(data2); //1 sec RenderSection3(data3); //1 sec RenderSection4(data4); //1 sec RenderSection5(data5); //1 sec }
source share