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

答题逻辑添加缓存 #118

Closed
everything411 opened this issue Dec 17, 2023 · 3 comments
Closed

答题逻辑添加缓存 #118

everything411 opened this issue Dec 17, 2023 · 3 comments
Labels
type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Comments

@everything411
Copy link
Member

everything411 commented Dec 17, 2023

用户答题答案不应每次都更新入数据库,而应该增加一层缓存,选取合适节点统一提交数据库,从而提升性能,防止被高峰挤爆。

考虑使用进程内缓存或者redis。


更新:可能需要 celery 定时任务。
BITNP/clinic_django@1999ae2

@YDX-2147483647 YDX-2147483647 added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Dec 17, 2023
@YDX-2147483647 YDX-2147483647 pinned this issue Jan 12, 2024
@InitialMoon
Copy link
Collaborator

实现了一个redis缓存版本 在add_redis 分支中

实现逻辑:每次update_response的时候就将post内容存储在redis中,键值是学号(student.user字段),最后提交的时候从redis中按照学号取出最新的post内容进行和之前update中相同的操作逻辑,还有优化的空间,就是不要循环遍历每一个选项都存储一次,而是将要存储的对象都存在列表中然后在一次存入,可以再提升20倍性能,之前是1+2+....+20=210次向数据库的写入,现在是20次(仅提交的时候进行)(假设redis的速度很快相对与原本的数据库几乎不计的话),性能提升应该是10倍左右,不过批量存储的方法没看懂之前实现的逻辑,怕改动造成更多bug,所以暂时没做,希望能在xyc的指导下作进一步的优化,变成一共只进行一次写入,这样就是200倍的性能提升?

@InitialMoon
Copy link
Collaborator

add_redis分支中没有改写test逻辑,现在test会有错误报告,因为update实现逻辑变了,所以是正常的报错,可以有空来写一写,测试redis键值是否存在即可
image

@YDX-2147483647
Copy link
Collaborator

Closed by #148.

@YDX-2147483647 YDX-2147483647 unpinned this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants