locked
What is the difference in 3-tier architecture and gereral way of programming in asp.net C# ? RRS feed

  • Question

  • User-2139107288 posted

    Hello friends,

    I want to know that What are the factors if we use methods on each .cs page for connection and executing query on each aspx code behind page rather then using  BAL .

    How our application get affected in terms of performance and speed or other way?

    when we put our website on server after publish/compile in general approach (using query in C# code behind) rathor than using stored procedures?

    then which logic is better and why ?

     

     

    Thursday, May 20, 2010 6:16 AM

Answers

  • User-952121411 posted

     

    I doubt that a call outside your application domain but in the same process is 1000 times slower then a call inside your application domain.

    You are welcome to check out the link I provided and question Rocky yourself on the details of it.  I believe the details he wrote, as he is a trusted member of our community writing several books on Business Objects and creator of the CSLA.NET Framework.  The fact of 1000 times could be 1/1000 of a nano second vs 1 nano second so thats why I say it is barely noticeable in my experience, but yes I still believe the comment. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 24, 2010 8:48 AM
  • User-2004844803 posted

    ok, I got it Smile

    this guy is a guru and have steped on some toes here for question his way off saying that its 1000 times slower when crossing a process boundary. But I am sorry, I dont agree when he says that it's always 1000 slower (but I do agree with the rest off his article). The cost off crossing a process (or domain) boundary can vary a lot depending on things like what kinda data you send, how big chunks you are sending and how you configure your application. Sure, in many cases its way more then a 1000 times slower. But, as an example, you move a string a cross a domain boundary with almost no cost at all. My point is that you can't generalize it like that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 24, 2010 5:15 PM

All replies

  • User1893362295 posted

    Hi,

    If we use stored procedures to do the data operations and some related operations, the advantage in performance is that, database connection counts will be reduced, since at the data side itself, we can do upto a level logical operations too.

    But it depends on how you optimize the usage of stored procedures according to your requirement.

    Thursday, May 20, 2010 8:52 AM
  • User291138276 posted

    Another advantage to using a layered application architecture is that you will have a solution where the "concerns" are centralized (data access is in one location, UI operations are in one location...). This leads to cleaner, more managable code. Of course, this implementation takes a bit of upfront work and may be overkill for trivial projects.

    Thursday, May 20, 2010 9:45 AM
  • User-1704326042 posted

    Hello guptaneelesh,

    It is a nice question.

    First, if you simply embed everything, and not use layers, maintenance is extremely painful and costly, Also, there's a high risk of regression.

    recently I worked on a sharepoint project, which had a simple web app. which displays reports, yet, all the C# was in one default.aspx page, and one data access class. 

         It took me forever to debug, having inline 45 if statements in 900+ lines of code (best practice is 600 unless the code is generated and automatically maintainted). 

         We had a bug, we looked all over the place, tried debugging, and finally a member of the BI team, asks us what we do with a paramter. Guess what, Ctl + F in the entire solution, that parameter was a query in the C#, in the data access layer. there's goes half a day of non productive work.

    About stored procedures :

         If you want to use text queries instead, it must be parameterized queries (although stored procedures are so important to the scalability of any projects).

         Once, in one application, to make a independency injection test, in one application which used the 'sa' account, I backed up the database manually, then, through a textbox in a form, I wrote a statement, which simply dropped the database from the server.

         Also, recently, a DBA was just so furious that some major queries were not stored procedures, which led to difficulties in analysing them and profiling them, when we had performance problems.

    About Layers :

        up until .net 2.0, developing layered architecture was painful. with ORM tools like nhibernate, and Entity frameowrk in 3.5, plus the enterprise library, the upfront work required to develop layered apps is worth the while, since it will cost later on in maintenance. 

        with the entity framework for example, for simple apps, you end up writing very little code, and you can always use stored procedures for your complex queries, and having other business objects.

        In multi-tier applications, the most costly part is the repetitive code required for CRUD operations, which has been well adressed by Microsoft since .net 3.5 and othe products.

    http://www.asp.net/community/projects

    I hope this gives you some info, and do not hestiate to take a looks at the asp.net starter kits, nothing better than code, to study the situation. I developed many projects using some of the asp.net starter kits, to get the techniques required (for ex.: Shopping cart, Images and database, Security, n-tier best practices, skins and themes etc...)

    I hope helps guide you a little :)


    Thursday, May 20, 2010 11:11 AM
  • User-2004844803 posted

    What is the difference in 3-tier architecture and gereral way of programming in asp.net C# ?

    Hi, I read the subject off your question but I cant really connect it to the rest off the text. Anyway, in general asp.net programming you take advance off IIS that is a complete application server that is capable off executing more then one off your logical layers (UI, BL etc). A 3-tier architecture on the other hand separates these logical layer into separate physical tiers where you run your UI on a Web Server and your BL on a dedicated Application Server.

    I want to know that What are the factors if we use methods on each .cs page for connection and executing query on each aspx code behind page rather then using  BAL .

    If using a BAL is separating your business logic into a separate layer where you package it in its own dll that you reference and use from your code behind then there should be no performace loss at all. On the other hand, if your BAL is running on a separate tier you need a way to communicate your data from one tier to the other. How big your performance loss is then is hard to say, it depends on how much data you send etc.

    The conclusion here is that there is a difference in tiers and layers. layers are only a way to logically separate your code while tiers is a physical separation off you layers.


    Thursday, May 20, 2010 3:29 PM
  • User-952121411 posted

    I want to know that What are the factors if we use methods on each .cs page for connection and executing query on each aspx code behind page rather then using  BAL .

    How our application get affected in terms of performance and speed or other way?

     

    In the simplest form of an answer, there technically should not be any noticeable performance difference based on placing the code directly behind or in its own logical layer.  This response is in complete disregard to the better approach for designing application, but that was not really your original question; it was centralized around performance.

    I will actually say that there is some documentation that states even crossing boundaries on the same machine (i.e. a separate binary) can be slower that everything running in the same memory space (from http://www.lhotka.net/WeBlog/PermaLink.aspx?guid=efa88d0a-2388-4909-bee1-c9bddb6e9868):

    "Crossing a boundary is expensive. It is on the order of 1000 times slower to make a call across a process boundary on the same machine than to make the same call within the same process. If the call is made across a network it is even slower. It is very obvious then, that the more boundaries you have the slower your application will run, because each boundary has a geometric impact on performance."

    Now I have never seen any noticeable performance loss of separating out code into logical layers (not tiers) but apparently it does exist.  I do not however think for most cases especially with today's even mediocre hardware that the point above is justification for placing all of the code in the page behind class on a mid-large size project.  I think that all of the points mentioned previously about maintainability, scalability, etc. far outweigh any support for the performance gains based on having a fat UI in an ASP.NET application.

    Friday, May 21, 2010 9:25 AM
  • User-2004844803 posted

    "Crossing a boundary is expensive. It is on the order of 1000 times slower to make a call across a process boundary on the same machine than to make the same call within the same process. If the call is made across a network it is even slower. It is very obvious then, that the more boundaries you have the slower your application will run, because each boundary has a geometric impact on performance."

    I doubt that a call outside your application domain but in the same process is 1000 times slower then a call inside your application domain. You can for example use WCF and if you are running on the same process you can use the net.pipe configuration and thats not 1000 times slower, not even close to that!

    But yes, I agree, dont separate into different tiers if you dont need to. And yes, separate into layers, you could even use more then 3 layers, as long as it adds a value to your architeture. And last, look into domain driven design, a domain model might really help you and your organization to understand your business needs, it has sure helped us a lot!


    Saturday, May 22, 2010 3:35 AM
  • User-952121411 posted

     

    I doubt that a call outside your application domain but in the same process is 1000 times slower then a call inside your application domain.

    You are welcome to check out the link I provided and question Rocky yourself on the details of it.  I believe the details he wrote, as he is a trusted member of our community writing several books on Business Objects and creator of the CSLA.NET Framework.  The fact of 1000 times could be 1/1000 of a nano second vs 1 nano second so thats why I say it is barely noticeable in my experience, but yes I still believe the comment. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 24, 2010 8:48 AM
  • User-2004844803 posted

    ok, I got it Smile

    this guy is a guru and have steped on some toes here for question his way off saying that its 1000 times slower when crossing a process boundary. But I am sorry, I dont agree when he says that it's always 1000 slower (but I do agree with the rest off his article). The cost off crossing a process (or domain) boundary can vary a lot depending on things like what kinda data you send, how big chunks you are sending and how you configure your application. Sure, in many cases its way more then a 1000 times slower. But, as an example, you move a string a cross a domain boundary with almost no cost at all. My point is that you can't generalize it like that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 24, 2010 5:15 PM