Mongodb千万级数据在python下的综合压力测试及应用探讨
来源:互联网 发布:湖北楚天网络 编辑:程序博客网 时间:2024/05/20 12:23
1
2
3
4
5
cat /etc/yum.repos.d/
10
.repo
[10gen]
name=10gen Repository
baseurl=http:
//downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=
0
1
2
3
4
5
6
7
8
9
10
11
12
13
from pymongo
import
* # 导包
con = Connection(...) # 链接
db = con.database # 链接数据库
db.authenticate(
'username'
,
'password'
) # 登录
db.drop_collection(
'users'
) #删除表
db.logout() # 退出
db.collection_names() # 查看所有表
db.users.count() # 查询数量
db.users.find_one({
'name'
:
'xiaoming'
}) # 单个对象
db.users.find({
'age'
:
18
}) # 所有对象
db.users.find({
'id'
:
64
}, {
'age'
:
1
,
'_id'
:
0
}) # 返回一些字段 默认_id总是返回的
0
不返回
1
返回
db.users.find({}).sort({
'age'
:
1
}) # 排序
db.users.find({}).skip(
2
).limit(
5
) # 切片
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
from pymongo
import
Connection
import
time,datetime
import
os,sys
connection = Connection(
'127.0.0.1'
,
27017
)
db = connection[
'xiaorui'
]
def func_time(func):
def _wrapper(*args,**kwargs):
start = time.time()
func(*args,**kwargs)
print func.__name__,
'run:'
,time.time()-start
return
_wrapper
@func_time
def ainsert(num):
posts = db.userinfo
for
x
in
range(num):
post = {
"_id"
: str(x),
"author"
: str(x)+
"Mike"
,
"text"
:
"My first blog post!"
,
"tags"
: [
"xiaorui"
,
"xiaorui.cc"
,
"rfyiamcool.51cto"
],
"date"
: datetime.datetime.utcnow()}
posts.insert(post)
if
__name__ ==
"__main__"
:
num = sys.argv[
1
]
ainsert(
int
(num))
1
2
3
4
5
6
7
8
9
10
11
12
def goodinsert(a):
posts.insert(a)
def ainsert(num):
for
x
in
range(num):
post = {
"_id"
: str(x),
"author"
: str(x)+
"Mike"
,
"text"
:
"My first blog post!"
,
"tags"
: [
"mongodb"
,
"python"
,
"pymongo"
],
"date"
: datetime.datetime.utcnow()}
# goodinsert(post)
a=threading.Thread(target=goodinsert,args=(post,))
a.start()
1
2
3
cat /etc/security/limits.conf
* soft nofile
102400
* hard nofile
102400
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat /etc/sysctl.conf
net.ipv4.tcp_syncookies =
1
net.ipv4.tcp_tw_reuse =
1
net.ipv4.tcp_tw_recycle =
1
net.ipv4.tcp_timestsmps =
0
net.ipv4.tcp_synack_retries =
2
net.ipv4.tcp_syn_retries =
2
net.ipv4.tcp_wmem =
8192
436600
873200
net.ipv4.tcp_rmem =
32768
436600
873200
net.ipv4.tcp_mem =
94500000
91500000
92700000
net.ipv4.tcp_max_orphans =
3276800
net.ipv4.tcp_fin_timeout =
30
#直接生效
/sbin/sysctl -p
1
多核问题可以在启动时加入启动参数: numactl --interleave=all
1
2
3
posts = db.userinfo
for
i
in
posts.find({
"author"
:re.compile(
'^2.Mike'
)}):
print i
0 0
- Mongodb千万级数据在python下的综合压力测试及应用探讨
- MongoDB千万级数据的分析
- 探讨下Tag标签的数据库设计(千万级数据量)
- 千万级数据库分页 与aspnetpager 的联合应用
- MONGODB的压力测试
- 通过分布式设计及文件级数据缓存打造千万级别WEB应用
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试(转)
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试-强哥
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- Mongodb亿级数据量的性能测试
- PHP,My Sql 备忘
- Masonry介绍与使用实践:快速上手Autolayout
- Spring 学习笔记-- <mvc:default-servlet-handler />默认加载simpleurlhandlermapping
- Swift - 序
- 结构型模式-外观模式
- Mongodb千万级数据在python下的综合压力测试及应用探讨
- SUSE助力SAP HANA实现高可用性
- Linux上强大的编译器gcc
- 文件操作
- 多校 hdu 5294 Tricks Device 最短路+最大流
- 三款开源关系型数据库对比:MySQL、PostgreSQL、SQLite
- Git stash和stash pop命令
- Leetcode Q2: Add Two Numbers
- Java中String类的方法及说明