Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求合并 #5

Open
DCjanus opened this issue Aug 25, 2018 · 3 comments
Open

请求合并 #5

DCjanus opened this issue Aug 25, 2018 · 3 comments

Comments

@DCjanus
Copy link
Owner

DCjanus commented Aug 25, 2018

短时间内多个相同请求可能同时触发多个相同的、对上游的HTTP请求,类似于缓存击穿的场景。

一种解决方案是:请求者获取当前数据库中最新的缓存,这个缓存可能已经超时;随后将更新请求放入队列,后台进程去重并串行更新。
另一种解决方案是:由统一的模板管理所有更新请求,请求者所在的web framework handler中可以拿到对应资源的token,并暂时阻塞其所在的线程/协程,待更新任务完成,唤醒所有持有对应资源token的线程/协程。

但前者实现较为丑陋,后者实现在当前线程池模型下成本较高,待async生态丰富后进行实现。

@DCjanus
Copy link
Owner Author

DCjanus commented Sep 9, 2018

暂时实现前者

@DCjanus DCjanus closed this as completed Sep 9, 2018
@DCjanus DCjanus reopened this Sep 9, 2018
@VillanCh
Copy link

Redis 一把梭

@DCjanus
Copy link
Owner Author

DCjanus commented Oct 19, 2018

这和Redis也没关系,单纯是现在没上协程,Redis也不能处理等待的问题。
缓存击穿最简单的办法是互斥锁,但互斥锁sleep的做法对线程模型不友好,所以需要等协程。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants