惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 深夜

AMIS中的组件添加图标的一些注意点。 VSCode 运行go test显示打印日志 现在CSDN真的很讨厌,百度出来都是一堆CSDN的东西。 VScode中的golang代码规范太严格,怎么处理。 chromedp自动启动为headless模式 chromedp下载文件的方法,备忘一下。 vue项目里的日期格式化(摘录) 深入分析 Java 中的中文编码问题 高亮显示web页表格行 tomcat作为windows服务的参数配置,特别是PermSize的设置 webwork和spring多配置文件的方法 - 深夜 - 博客园 webwork的interceptor来实现ajax功能(buffalo) 用C#实现BHO(Brower Helper Object) 用Sitemesh控制页面布局 关于WebWork2中的中文问题 tomcat中的几点配置说明 使用Filter实现静态HTML缓冲(一种折中方法) 关于DirectX中的DirectShow介绍 基于Delphi的VFW视频捕获程序的开发
同一个浏览器多次请求竟然发现是串行执行的,见鬼了。
深夜 · 2022-02-21 · via 博客园 - 深夜

今天在对一个执行时间比较长方法做下控制,本想是多次请求访问的时候,同时只有一个在执行这个耗时的方法,其他请求能够直接返回当前状态。如下:

//触发一次账号同步
func SyncNow(c *gin.Context) {
	account := c.Param("account")
	pwd := c.Param("pwd")

	//这些写死了认证账号和密码
	if (account == "账号") && (pwd == "密码") {
		if !running {
			running = true
			ldap.StartSyncNow()
			running = false
			c.JSON(http.StatusOK, gin.H{"status": 0, "msg": "账号同步完成。"})
		} else {
			c.JSON(http.StatusOK, gin.H{"status": 5, "msg": "账号同步正在运行中..."})
		}
	} else {
		c.JSON(http.StatusOK, gin.H{"status": -1, "msg": "验证信息错误。"})
	}
}

结果发现,在同个浏览器上访问,多个请求都在排队执行,不会立马返回,真的见鬼了,我还以为gin的controller方法是单例的,但是感觉也不像,但是网上没找到相关的资料。
后来在CSDN上发现了这篇文章SpringBoot的controller为什么不能并行执行?同一个浏览器连续多次访问同一个url竟然是串行的?

对,是chrome浏览器或使用了相同内核的浏览器引起的。
谷歌浏览器同时只能对同一个URL发起一个请求,如果有更多的请求的话,则会串行执行。如果请求阻塞,后续相同请求也会阻塞。

Chrome的限制规则是:浏览器同时只能对同一个URL提出一个请求,如果有更多的请求的话,对不起,请排队。这个所谓“限制”到底好不好?可能不错,想想对同一URL的请求,如果前请求阻塞,那么后请求想必也会被阻塞,这无端增加了开销,并没多大意义,Chrome这么做应该有它的合理性。

为此为了验证这个上面这段话,我们可以找到这么一篇文章:Http cache:Implement a timeout for the cache lock.

https://codereview.chromium.org/345643003