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

mongodb操作优化 #754

Merged
merged 1 commit into from Mar 15, 2018
Merged

mongodb操作优化 #754

merged 1 commit into from Mar 15, 2018

Conversation

plusplus1
Copy link
Contributor

1、去掉连接后ensure_index操作

当result、task 表数据量较大时,启动后建索引会等待很长时间,尤其是分布式部署情况下,每个进程启动后都会重建索引

2、优化taskdb stat_count操作

aggregate做分组统计时进行全表扫描,比较慢,实际项目种导致scheduler模块启动时长接近30min,
考虑到status字段有索引,直接进行count统计反而效果比较好
实测效果优于aggregate操作

collection_name = self._collection_name(project)
self.database[collection_name].ensure_index('status')
self.database[collection_name].ensure_index('taskid')
# we suggest manually build index in advance, instead of indexing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it re-index if the field has indexed before?

@binux binux merged commit 87337e7 into binux:master Mar 15, 2018
brian6peng pushed a commit to brian6peng/pyspider that referenced this pull request Jun 20, 2018
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

Successfully merging this pull request may close these issues.

None yet

2 participants