问题描述:
由于在做mysql数据库压力测试,现在表中没有外键引用,每张表中都有字段做了索引,测试中插入数据量有几千万条,
但我发现插入到十几万条的时候,插入的速度会急剧下降,主机内存也消耗非常大(差不多2G,总共3G)。之后就会死机,动也不动,而且mysql数据库表中的数据也几乎没有插入。
疑问 :
 我想请教大家我需要考虑哪些潜在的因素,以及配置文件应该怎么修改,还有就是应该去查找哪方面的资料?
谢谢了!

解决方案 »

  1.   

    测试部分的代码如下:@logtime
    def driver(n):
        user = User()
        photo = Photo()
        qpoint = QPoint()
        comment = Comment()
        for i in range(0,n):
            gen_user(user)
            user.save()        photo_cnt = random.randint(1, 10)
            for j in range(1, photo_cnt):
                gen_photo(photo, user.uid)
                photo.save()            qpoint_cnt = random.randint(0,3)
                for k in range(1, qpoint_cnt):
                    qpoint_creater = random.randint(0, 10000000)
                    gen_qpoint(qpoint, photo.pid, qpoint_creater)
                    qpoint.save()                comment_cnt = random.randint(0, 4)
                    for c in range(1, comment_cnt):
                        comment_creater = random.randint(0, 10000000)
                        gen_comment(comment, qpoint.qid, comment_creater)
                        comment.save()
    生成对象对内存的消耗并没有太大影响,因为对象都是重用的
      

  2.   

    不懂Python,看不出怎么个插入流程~
    写个伪代码吧,不懂Python的也好帮你~
      

  3.   

    ok, 测试伪代如下:for i in 2000000:
       generate a 
       save a
       photo_cnt = random(1,10)  #产生1~10之间的随机数photo_cnt
       for j in photo_cnt:       #从0开始遍历photo_cnt
          generate b
          save b
          qpoint_cnt = random(0,3)
          for k in qpoint_cnt:
             generate c 
             save c
             comment_cnt = random(0,4)
             for l in comment_cnt:
                 generate d
                 save d帮帮忙,以前没做过这方面的测试,很棘手。
      

  4.   

    我测的时候n等于2百万,推算总共数据,大概3千万条,我觉得跟mysql的数据库使用的引擎有关系,缺省的是
    Myisam,可能我们更适合使用InnoDB,测测看!
    还有这个插入应该是分段来插的,谢谢提醒,因为写入缓存的而来不及执行插入的数据可能是占用内存的重要原因。