ASP.NET MVC Web - How to separate performance between the modules of a project?

Asked

Viewed 725 times

2

Explaining the doubt. Within my system there are some menus, we will use as example 3, naming them A, B and C, each being a CRUD module with some kind of report. If 300 people are using module A, it will impact the performance of module B, right? 300 people ordering something from the bank at the same time, etc. Not to mention that it also influences the performance of the server that the system is published (IIS), so far it is correct? Correct me if I’m wrong, please.This counts for any other module. How do I make a specific module not influence the performance of other modules? This is what the client is asking to do in a single module. Would API solve it? I’m not familiar with the usability of the API. If anyone here knows and tells me that this would separate this "problem" from performance, I will look for more information to develop. Or Web-Service? Finally, immediately my project manager 'suggested' to do another project mvc same, also separating the banks, and call by iframe. Would that be the best solution? I think it was very funny to do this, and I still don’t know what the login part would look like, since it would come from the 'original' system, and not from the project inside the iframe.

3 answers

5

As the Gypsy has already listed very well the points of his doubt and responded to the height, I will just suggest some links and make some suggestions for technologies to be used.

How are you using the ASP.NET MVC check if all your Actionare marked with return async Task<>.

So where do you find.:

public class MyController : Controller
{
    public ActionResult MyAction(int id)
    {
        var model = db.Colecao.Find(id);
        return View(model);
    }
}

change to.:

public class MyController : Controller
{
    public async Task<ActionResult> MyAction(int id)
    {
        var model = await db.Colecao.FindAsync(id);
        return View(model);
    }
}

The same goes for Webapi, so find yourself.:

public class MyController : ApiController
{
    public Entidade MyAction(int id)
    {
        var model = db.Colecao.Find(id); 
        return model;
    }
}

change to.:

public class MyController : ApiController
{
    public async Task<Entidade> MyAction(int id)
    {
        var model = await db.Colecao.FindAsync(id);
        return model;
    }
}

With this, you make your Asynchronous Actions, with this simple change your system can come to support thousands of requests per minute, as you can see in the following Artigo/Benchmarking - Node.js vs. IIS + WebAPI async – Performance Test

Now as to Banco de Dados, you can and should make use of and abuse of Entity Framework to speed up its development, just remember to use asynchronous methods whenever they are available.: for example FindAsync, ToListAsync, ToDictionaryAsync, FirstOrDefaultAsync, AnyAsync, MeuMetodoAsync.

But remember, the Entity Framework is just a tool, nothing prevents you from using another in conjunction with it, as for example the Dapper, I advise you to use the Dapper whenever you have a more critical query for the system, either because it is very requested or if you need to write your own SQL, in any case, be sure to use the methods Async, like the QueryAsync . Here is a link to justify this advice.: Dapper vs Entity Framework vs ADO.NET Performance Benchmarking

As for your front-end, as I do not know the knowledge that your team has of Javascript, I would advise you to put aside the jQuery and use the VueJS, even if they decide to make a Multiple Page Application.

Model

public class Entidade
{
    public Int32 EntidadeID { get; set; }
    public String Descricao { get; set; }
}

Controller

public class MyController : Controller
{
    public async Task<ActionResult> MyAction(int id)
    {
        var model = await db.Colecao.FindAsync(id);
        return View(model);
    }
}

Controller

@model Entidade
<div id="conteudo">
    <input type="hidden" id="EntidadeID" name="EntidadeID" v-model="EntidadeID">
    <label>
        Descrição: 
        <input type="text" id="Descricao" name="Descricao" v-model="Descricao">
    </label>
</div>
@section scripts {
    <script type="text/javascript">
        var model = @(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model)));
        new Vue({
            el: '#conteudo',
            data: model
        });
    </script>
}

At first glance it seems a bad exchange (O Razor for Vue), but remember, you will be transferring the responsibility of rendering the page to the Cliente, and will be much simpler to update the page after requests AJAX (due to bind bi-direcional created by VueJS).

To learn more, visit the links.: VueJS, Vue JS Brasil and Vue.js is easier to learn than jQuery.

Remembering that the adoption of VueJS can be incremental, you don’t need to rewrite your entire application in order to start using the same.

Of course, you may come to make an application SPA, using the Async WebAPI and the Framework JavaScript of your preference, such as Angular, React or the very VueJS, follows a tutorial link VueJS - Single Page Application

  • I appreciate the tips, and I will certainly look into those cases. The system was developed in 2012, and several developers programmed into the project, each using their development practices, and in some cases, development practices, ta a true Frankenstein. A few weeks ago I even thought about taking a look at this issue of using async in actions, because I needed to use it in a specific action. If I change all actions to async I won’t run the risk of giving any trouble then?

  • In this case, I advise you to do this progressively, write the new features this way, and when you need to change an old one, modify it to fit this new model. As for exchanging Actionresult for async Task<Actionresult>, it should not impact your solution, yet I would make this change slowly.

2

If 300 people are using module A, it will impact the performance of module B, right?

Yes, because it’s one system, but 300 people usually don’t even tickle the service if you use the right practices for databases, asymchronism and good strategies cache.

300 people ordering something from the bank at the same time, etc. Not to mention that it also influences the performance of the server that the system is published (IIS), so far it is correct?

Yeah, but, like I said, it’s too early to think about solving performance. First you need to measure how the server behaves before proposing something to solve, in the sense of modularization, which is what your question proposes to elucidate.

How I do for a specific module does not influence the performance of other modules?

As I said, using the right practices for databases, asymchronism and good strategies cache.

Would API solve it? I’m not familiar with the usability of the API. If anyone here knows and tells me that this would separate this "problem" from performance, I will look for more information to develop. Or Web-Service?

(Web) API and Web Service are almost the same thing. The difference is that one implements REST and the other implements SOAP. Regardless of implementation, this has little or nothing to do with performance as a whole.

Anyway, at once my project manager 'suggested' to do another project mvc same, also separating the banks, and call by iframe. It would be the best solution?

Not at all. The server work is the same and still incurs a bad practice of using <iframe> where you don’t need.

I think it was very funny to do this, and I still don’t know what the login part would look like, since it would come from the 'original' system, and not from the project inside the iframe.

And indeed, it is.

If you need advice on this, check my contact details. I can do a more in-depth consulting on your problem.

  • Just to complement Node.js vs. IIS + Webapi async - Performance Test, As you can see, IIS can process 100,000 requests per minute. What about the Database Dapper vs Entity Framework vs ADO.NET Performance Benchmarking, depedendo of the requisition it takes less than 1 millisecond.

  • Aside from the part where iframe is bad practice, you said the server job would be the same. However, this project called by iframe would be on another server, and the database also, separate from the original database'.

  • @Would Yoshitani and the two banks communicate through Linked Server? If Yes... I can already feel their suffering in the future ;D

  • They would not communicate. What I need to use from the 'original' database, I do via sql query. And the FK of the new database, are unrelated. It was the only thing I thought to do the way I was asked.

  • @Yoshitani instead of breaking your database, try to identify where the bottleneck is, if the bottleneck is from IO, try to put the file of Dados, Log and arquivo de indices in HDdifferent s, if not solve, create Filegroups and distribute your tables on them. Now if the problem is CPU, create a Cluster de SqlServer

  • You still haven’t answered me whether you have a performance bottleneck or not. If the idea is to ~separate by modules~, physically placing a server and a database per module, the communication between them should be by Web API.

Show 1 more comment

1

I endorse the answers of the Gypsy, but in the question below , I am of another opinion. But it doesn’t mean it’s my answer or his is right or wrong or worse or better.

Anyway, at once my project manager 'suggested' to do another project mvc same, also separating the banks, and call by iframe. It would be the best solution?

Search for never use IFRAME, really is a bad practice - really gambiarra. But to separate the modules, each one in a project, this is appropriate to talk. I have seen many projects where there is no need to have a monolithic design, and the system starts to become complex just by trying to keep everything in one environment. And if it’s segmented, everything becomes clearer and lighter.

It’s not hard to begin to understand if this separation is interesting. A shallow pre-analysis that I start by asking: What is the data flow? If the answer is something like:

  1. The entity/data is started and prepared in Module A;
  2. Module B only handles information that Module A allows;
  3. Module C only handles information that Module B allows;

So it is easy to see that the modules are fully decoupled. They can easily be different designs, independent database, and everything else.

A cool example is a store, where you can have 3 totally independent systems:

  1. LOGISTICA (PHP+Mysql): From shopping and receiving new products. After the product is ready to be sold, it is sent to the SHOP.
  2. SHOP (SAP+Nodejs+Mongodb): Receive the product, publish in the store, add in the shopping cart and make the sale.
  3. ACCOUNTING (ASP.NET+Sqlserver): Receives the purchase order, validates and effective the sale, shoots message to the logistics make the delivery.

A solution, but several projects, with various technologies. Logistica does not need to know that there are customers, nor purchasing processes. The Shop does not need to know that there are truck delivery procedures, how the products are organized in stock, etc. And the Accounting just need to know of purchase orders, and money, need not know anything about customers or trucks.

Finally, separating your solution by scope of responsibilities is healthy yes, as long as necessary and know how to do.

  • I understand, but a doubt: in the example you mentioned, as LOJA would be part of the same system as LOGISTICA, and each one would be a menu in the system as a whole. I will use this page I am now stackoverflow even, have the menus 'Questions', 'Tags', 'Users', by hovering over we can see that the link is the same, just changing after the "/", what I would like to do is the menu "Users" for example, did not influence the performance of the rest. Can have millions of users using, slowing down only the page users, not the entire system.

  • But each /modulo can be a different application without problems. In IIS vc can create Application Folders, or else you can create subdomains like moduloA.seudominio.com, moduloB.seudominio.com. So this is not a problem, you should just choose how you will publish your applications.

  • In the example I made, the SHOP will have millions of accesses, while others will be accessed only by the employees of the store. And you can have in the menu loja.com, loja.com/logistica, shop.com/accounting` no problem.

  • So, but being on the same server, these millions of access in the STORE, would impact the performance of logistics, no?

  • You can isolate the processing of the application to limit resource consumption. Another thing is that it is not mandatory to host the application on the same server. Ideally each application has its own hosting

  • Especially if we’re talking about cloud hosting. If so, other ls concerns should be raised in order to get the most out of your cloud provider.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.