Code Monkey home page Code Monkey logo

hellocaching's Introduction

ASP.NET Core性能优化

避免阻塞调用

ASP.NET Core应用应设计为可同时处理许多请求。异步API允许较小线程池处理数千个并发请求,无需等待阻塞调用。线程可以处理另一个请求,而不是等待长时间运行的同步任务完成。

ASP.NET Core应用中的一个常见性能问题是阻塞可以异步进行的调用。许多同步阻塞调用都会导致线程池饥饿和响应时间降低。

禁止行为

  • 通过调用Task.WaitTask<TResult>.Result.
  • 获取常见代码路径中的锁。当构建为并行运行代码时,ASP.NET Core应用的性能最高。
  • 调用Task.Run并立即等待它。ASP.NET Core已经在普通线程池线程上运行应用代码,因此调用Task.Run只会导致不必要的额外线程池计划。即使计划的代码会阻止某个线程,Task.Run也不会阻止该线程。

建议做法

  • 使热代码路径成为异步。
  • 如果有异步API可用,则异步调用数据访问、I/O和长时间运行的操作API。请勿用于Task.Run使同步API异步。
  • 使控制器/RazorPage操作成为异步。为了获益于async/await模式,整个调用堆栈都是异步的。

相关文章

hellocaching's People

Contributors

taylorshi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.