在 Django 缓存中高效存储大表
我使用 Django 和 jqGrid 并通过 AJAX 加载页面。有时,查询非常复杂,页面加载速度非常慢,远距离页面加载速度要慢得多(这是可以预料的,结果通常会超过 100k 对象)。我认为结果缓存可以解决问题,为第一页的加载增加一些时间,但随后会大大加速后续页面的加载。
相反,它使首页的加载速度极其缓慢,甚至后续页面也需要花费大量时间(在标准 PC 上为 11 秒)。我正在使用 locmem 缓存后端。 有什么想法吗?为了进行比较,我尝试将结果存储在全局字典中,这要好得多(后续页面只需要 1 秒),但我听说这不是一种安全的方法。
有什么想法吗?
I use Django with jqGrid and loading pages via AJAX. At times, queries are very complex, and page loading is ver slow, for far pages is much slower (which is to be expected, the results often exceed 100k objects). I thought that result caching will solve the problem, adding some time to the loading of the first page, but then strongly accelerating the loading of subsequent pages.
Instead, it made the loading of the first page incredibly slow and even subsequent pages take a lot of time (11s on a standard PC). I'm using locmem cache backend.
Any ideas? I tried, for a comparison, storing results in global dictionary and that was MUCH better (subsequent pages take only 1s), but I've heard that it's not a safe way.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑预热您的缓存。这可以手动完成,或者使用像 celery 这样的排队框架,在另一个页面加载后在后台缓存后续页面或查询集。
看一下 johnny-cache,它执行透明的查询集缓存。这可能(我重复一遍,可能)解决您的所有问题。
You could look at warming your cache. This could be done manually, or using a queuing framework like celery to have the caching of subsequent pages or querysets happen in the background after another page load.
Have a look at johnny-cache, which does transparent queryset caching. This may (I repeat, may) solve all of your problems.