- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想知道如果您的代码并非所有部分都是异步的,那么使用异步 http 请求会带来多少好处。
让我们考虑以下场景:1) 异步 http 请求阻塞同步数据库调用,以及 2) 同步 http 请求等待异步数据库调用。
1) Web Api 支持异步操作方法,但是如果我在处理请求时执行同步数据库调用,那么线程会阻塞调用,我将无法获得异步可以给我带来的更好的线程经济性的好处,或者什么?
2) 如果我有一个等待异步数据库调用的同步 ServiceStack 服务调用,那么会发生什么?我假设一个线程被保留用于处理整个同步 http 请求,当这个线程等待异步调用时它仍然被保留给 web 请求或者什么?
基本上我的问题可以归结为:如果不是所有的 IO 调用都是异步的,是否有任何理由使用异步?
最佳答案
在服务器端,部分异步
解决方案通常没有任何好处。
1) Web Api supports async action methods, but if I do a sync database call when handling the request, then the thread blocks on the call, and I will not get the benefits of better thread economy that async could give me or what?
正确。一旦执行同步(阻塞)数据库调用,您就会在该调用期间占用一个线程。因此,您从 async
中获得的好处不适用。
2) If I have a synchronous ServiceStack service call that awaits an async database call, then what happens? I assume a thread is reserved for handling the entire sync http request, and when this thread awaits an async call then it is still reserved to the web request or what ?
这与同步数据库调用相同。在幕后,同步数据库调用异步执行实际调用,然后阻塞调用线程直到完成。因此,在调用期间您仍然有一个线程被阻塞,并且您没有获得任何 async
好处。
Basicallly my question can be boiled down to this: Is there any reason to use async if not all IO calls are async?
还有一些更晦涩的场景。您可以使用 Task.WhenAll
进行有限类型的并发,使用 async
比使用其他形式的异步并发要容易得多。但如果您没有完全 async
堆栈,这是我能想到的唯一好处。
关于c# - 当并非所有代码部分都是异步时,异步 Web 服务有什么好处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16840878/
如果函数定义顺序不对,Jslint 将指出错误。 显然 jslint 是严格的,但我想知道将函数按顺序排列是否有任何好处。 我的意思是在调用它们之前定义它们。 最佳答案 函数定义(和 var 语句)被
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我注意到Flask tutorial涉及到点的使用。看起来它只是用于在本地创建一个轮子,这将使服务器上的设置变得更容易,但作为一个网络开发新手,我很好奇:是否有人真的会一路将他们的网站上传到像 PyP
我一直在阅读有关 jquery live event 的内容,但仍然有点困惑?使用它有什么好处? http://docs.jquery.com/Events/live 我知道它与绑定(bind)类似,
这是我的故事:我已将我的应用迁移到 AndroidX,因为我需要从网上找到的库中获取一些新功能。 问题:我目前遇到了一些问题,因为我现在需要为 Cordova 开发一个插件来实现该应用程序的一部分。
在使用 RAD 或一般不使用单元测试时使用依赖注入(inject)是否有任何好处? 最佳答案 是的,有以下几个好处: 减少依赖 减少依赖携带 更多可重用代码 更多可测试代码 更具可读性的代码 更多引用
我目前正在构建一个通过 MSI Windows Installer 分发的产品。我们的客户正在使用不同的形式(例如我们在他们自己的 MSI 中)集成该产品,使用 Bootstrap /链接器(如 Wi
有人声称 Scala 的类型系统是图灵完备的。我的问题是: 这有正式的证据吗? 简单的计算在 Scala 类型系统中会是什么样子? 这对 Scala 这种语言有什么好处吗?与没有图灵完备类型系统的语言
我开始尝试使用 React,我注意到我正在制作的简单应用程序全部使用 JS。我的 html 页面只是一个空的 body 标签! 所以我有几个问题,因为我是这个框架的新手。 我的整个应用程序应该基本上都
我们有一个相当大的基于 Windows 的 1.1 .NET 应用程序,我们正在考虑升级到 2.0。我们考虑更新的主要原因是我们可以利用 Visual Studio 2008 进行项目的持续开发,以及
我有一个页面,其中内置了基于 ajax 的分页。分页用于页面中的“评论”功能。根据 Google 的网站管理员博客,具有 rel="next"和 rel="prev"值有利于 SEO。 我在头部添加了
我是一名优秀的程序员,十分优秀!