用德哥的测试方法,笔记本上跑的pg只有31tps正常吗?
listen_addresses = '0.0.0.0'
max_connections = 1000
superuser_reserved_connections = 13
unix_socket_permissions = 0700
tcp_keepalives_idle = 60tcp_keepalives_interval = 10tcp_keepalives_count = 6
shared_buffers = 1GB
maintenance_work_mem = 512MBshared_preload_libraries = 'auth_delay,passwordcheck,pg_stat_statements,auto_explain'
vacuum_cost_delay = 10msvacuum_cost_limit = 10000
bgwriter_delay = 10ms
’# wal_level = logical
wal_buffers = 16MB
checkpoint_segments = 64
checkpoint_timeout = 5min
‘# archive_mode = on
‘# archive_command = '/bin/date'
’# max_wal_senders = 32
random_page_cost = 2.0
effective_cache_size = 6GB #我的内存只有8G,80%大约就是6G
log_destination = 'csvlog'logging_collector = onlog_truncate_on_rotation = onlog_rotation_age = 1dlog_rotation_size = 10MB
log_min_duration_statement = 1000ms
log_checkpoints = on
log_connections = onlog_disconnections = onlog_error_verbosity = verbose # 在日志中输出代码位置
log_lock_waits = ondeadlock_timeout = 1s
log_statement = 'ddl'
track_activity_query_size = 2048
autovacuum = onlog_autovacuum_min_duration = 0
shared_preload_libraries = 'pg_stat_statements'
auth_delay.milliseconds = 5000 # 认证失败, 延迟多少毫秒反馈auto_explain.log_min_duration = 5000 # 记录超过多少毫秒的SQL当时的执行计划auto_explain.log_analyze = trueauto_explain.log_verbose = trueauto_explain.log_buffers = trueauto_explain.log_nested_statements = truepg_stat_statements.track_utility=offpg_stat_statements.max = 1000pg_stat_statements.track = all
就用上面的参数,跑的测试,基本上照抄的德哥的优化1的设置,前面加#号的是跟主备相关的测试,因为我的是笔记本,单台机器,所以,没有启用这些参数。
其实,后面几步,有的已经做了,有的没有,prepared模式没有打开,异步日志没有打开(在用默认的),pgfincore已经做了,用函数代替简单的sql语句,也已经做了。你的文章里的机器,一开始就能到300多,我的笔记本,一直在30多打转,不确定是不是初始参数,设得就不合理啊?
synchronous_commit = offwal_writer_delay = 10ms
加了异步日志,并使用了prepared的结果:
(backend)xxxxxx@Tower:~/workspace/test_postgres/sql$ pgbench -M prepared -r -c 8 -f login.sql -j 8 -n -T 180 -h localhost -U digoalPassword: transaction type: Custom queryscaling factor: 1query mode: preparednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 5792tps = 31.978472 (including connections establishing)tps = 31.983547 (excluding connections establishing)statement latencies in milliseconds:
0.003740 \setrandom userid 1 20000000
249.734626 SELECT f_user_login(:userid);
iostat -x显示util项跑满
avg-cpu: %user %nice %system %iowait %steal %idle
1.20 0.00 1.45 71.28 0.00 26.07
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %utilsda 0.00 22.00 130.00 40.33 1066.67 657.33 20.24 9.10 53.69 61.83 27.47 5.87 100.00
赞0
踩0