Mongodb具有非常高的CPU速率

时间:2014-09-10 13:38:14

标签: mongodb python-2.7 pymongo

当我运行以下代码并立即将其杀死(这意味着异常退出)时,Mongodb的CPU速率将会非常高(大约100%):

#-*- encoding:UTF-8 -*-

import threading
import time

import pymongo

single_conn = pymongo.Connection('localhost', 27017)

class SimpleExampleThread(threading.Thread):
    def run(self):
        print single_conn['scrapy'].zhaodll.count(), self.getName()
        time.sleep(20)

for i in range(100):
    SimpleExampleThread().start()

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
696m  35m 6404 S 1181.7  0.1 391:45.31 mongod

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

我的Mongodb版本是2.2.3。当Mongodb运行良好时,运行命令" strace -c -p" 1分钟给出以下输出:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 33.50    0.322951         173      1867           nanosleep
 33.19    0.319950         730       438           recvfrom
 21.16    0.203969          16     12440           select
 12.13    0.116983       19497         6           restart_syscall
  0.02    0.000170           2        73           write
  0.00    0.000016           0       146           sendto
  0.00    0.000007           0        73           lseek
  0.00    0.000000           0         2           read
  0.00    0.000000           0         3           open
  0.00    0.000000           0         3           close
  0.00    0.000000           0         2           fstat
  0.00    0.000000           0        87           mmap
  0.00    0.000000           0         2           munmap
  0.00    0.000000           0         1           pwrite
  0.00    0.000000           0         3           msync
  0.00    0.000000           0        29           mincore
  0.00    0.000000           0        73           fdatasync
------ ----------- ----------- --------- --------- ----------------
100.00    0.964046                 15248           total

当Mongodb的cpu率非常高(大约100%)时,运行相同的命令给出以下输出:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 29.12    5.064230        3088      1640           nanosleep
 28.83    5.013239       27851       180           recvfrom
 22.72    3.950399      658400         6           restart_syscall
 19.30    3.356491         327     10268           select
  0.02    0.004026          67        60           sendto
  0.01    0.001000         333         3           msync
  0.00    0.000269           9        30           write
  0.00    0.000125           4        30           fdatasync
  0.00    0.000031          10         3           open
  0.00    0.000000           0         2           read
  0.00    0.000000           0         3           close
  0.00    0.000000           0         2           fstat
  0.00    0.000000           0        30           lseek
  0.00    0.000000           0        57           mmap
  0.00    0.000000           0         2           munmap
  0.00    0.000000           0         1           pwrite
  0.00    0.000000           0        14           mincore
------ ----------- ----------- --------- --------- ----------------
100.00   17.389810                 12331           total

如果我运行命令" lsof",有许多袜子的描述"无法识别协议"。我不知道出了什么问题。 Mongodb中有一些错误吗?

谢谢!

0 个答案:

没有答案