Gao Conghui

好好学习,天天向上

爬虫,视频处理


mongodump 在数据量大的时候非常缓慢

这边的解决方案是增加 --forceTableScan

–forceTableScan

Forces mongodump to scan the data store directly: typically, mongodump saves entries as they appear in the index of the _id field. Use –forceTableScan to skip the index and scan the data directly. Typically there are two cases where this behavior is preferable to the default:

If you have key sizes over 800 bytes that would not be present in the _id index.

Your database uses a custom _id field.

When you run with –forceTableScan, mongodump does not use $snapshot. As a result, the dump produced by mongodump can reflect the state of the database at many different points in time.

我们知道,mongodb会把document存在dbname.1,dbname.2…的文件里边,当文档增多时,会新增新的dbname.n文件。mongodump默认会通过_id字段去读取文档。默认的objectId其实就是时间戳,使用objectid作为id的,mongodump时相当于按时间顺序去读取文档,会以此遍历dbname.n文件。

而我使用的是自己设的_id。mongodump遍历_id字段的顺序与时序关系不大,会随机访问dbname.n文件,产生大量的随机读。使用这个参数,可以不通过_id去读取。

mongodump默认使用snapshot,会通过扫描_id 索引,然后去读取实际的文档。TableScan会按照mongodb的物理存储顺序进行扫描,没有读取index的过程。但是tablescan潜在的问题是,如果一个文档在dump的过程中移动了(物理上),有可能会最终输出两次。

最近的文章

python实现redis三种cas操作

cas全称是compare and set,是一种典型的事务操作,本文会介绍三种redis实现cas事务的方法,并会解决下面的虚拟问题:维护一个值,如果这个值小于当前时间,则设置为当前时间;如果这个值大于当前时间,则设置为当前时间+30。简单的单线程环境下代码如下:# 初始化r = redis.Redis()if not r.exists("key_test"): r.set("key_test", 0)def inc(): count = int(r.get('key_tes...…

redis python继续阅读
更早的文章

python随笔之实现classmethod staticmethod

大概刚学python的时候就知道了classmethod和staticmethod的用法,后来看到描述器才知道描述器与他们之间千丝万缕的关系,是否能动手实现下这俩货嘞?这边先从bound和unbound method说起bound unbound看下面的例子class Cla(): def __init__(self,a): self.a = a def f(self): print self,self.a print Cla.f# &...…

python随笔继续阅读