Slides from Secon'2015 - Software Developers Conference. Penza, Russia.
The database is an essential element of any project. The database must be stable and provide good performance. If you plan to use PostgreSQL in your project, you will run into question the choice of operating system. Linux is one of the most popular operating system today. The combination of flexibility and stability makes Linux a good candidate as a platform for PostgreSQL. However, the default settings are suitable for a wide range of workloads. In this report, I will talk about what settings should pay attention and how they affect the performance of PostgreSQL. Which of these settings are more important, and what - no. How do the PostgreSQL more predictable and stable under normal circumstances or in cases of increasing load.
2. Пенза, 24 апреля 2015
2015.secon.ru
About:
● Алексей Лесовский
● PostgreSQL DBA
● Linux system administrator
PostgreSQL-Consulting.com
● Поддержка 24/7
● Аудит и оптимизация производительности
● Консультации и тренинги
● Мониторинг и аварийное реагирование
● Планирование ресурсов
3. Пенза, 24 апреля 2015
2015.secon.ru
Agenda
● Linux on PostgreSQL ?
● Resources and Databases
● OS subsystems
● CPU & Process scheduling, Power saving
● Memory & VM, NUMA, Huge Pages
● Storage & Filesystems, Input/Output
● Other misc
4. Пенза, 24 апреля 2015
2015.secon.ru
Intro.
● Linux as a platform for PostgreSQL database
●
Active development & Community support
●
Rich features & Fast implementation
●
Stable & Mature & Durable
● Default settings in Linux
5. Пенза, 24 апреля 2015
2015.secon.ru
Tuning targets
CPU
Disk
Memory
Concurrency
Query Speed
Sort, Group, Hash,...
OS cache (page cache)
DB cache (shared_buffers)
Operations (work_mem)
DB storage
Transactional Log (WAL)
Cold start
6. Пенза, 24 апреля 2015
2015.secon.ru
Tuning targets
CPU
Disk
Memory
CPU Scheduler
NUMA
Power saving
Virtual Memory
NUMA
Huge Pages
FileSystems
Storage I/O
7. Пенза, 24 апреля 2015
2015.secon.ru
Tuning targets:
● CPU scheduler
● Virtual memory and NUMA
● Huge pages
● File systems
● Storage IO
● Power saving policy
● Others
8. Пенза, 24 апреля 2015
2015.secon.ru
Tuning target: CPU scheduler
● CPU scheduler is ...
● sysctl: kernel.sched_migration_cost_ns
● sysctl: kernel.sched_autogroup_enabled
● http://www.postgresql.org/message-id/50E4AAB1.9040902@optionshouse.com
● http://kernelnewbies.org/Linux_2_6_38#head-59575a6aeafa38490226a560ee02de89829a5b20
9. Пенза, 24 апреля 2015
2015.secon.ru
Tuning target: CPU scheduler
● WARNING: should use update kernel because
●
Ubuntu 12.04 Bug #1055222,
●
Ubuntu 14.04 Bug #1422016
A kernel panic occurs while disabling the automatic task group creation
within /etc/sysctl.conf using "kernel.sched_autogroup_enabled = 0". After
adding the "noautogroup" kernel parameter to GRUB, the system will boot
without issue.
10. Пенза, 24 апреля 2015
2015.secon.ru
Tuning target: CPU scheduler
● pgbench tests:
$ pgbench -S -c 8 -T 30 -U postgres pgbench
transaction type: SELECT only
scaling factor: 30 duration: 30 s
number of clients: 8 number of threads: 1
sched_migration_cost_ns = 50000, sched_autogroup_enabled = 1
- tps: 22621, 22692, 22502
sched_migration_cost_ns = 500000, sched_autogroup_enabled = 0
- tps: 23689, 23930, 23657
24. Пенза, 24 апреля 2015
2015.secon.ru
Tuning target: Power saving policy
● acpi_cpufreq vs intel_pstate
● scaling_governor
●
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
●
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
● acpi_cpufreq + performance
● intel_pstate + powersave
25. Пенза, 24 апреля 2015
2015.secon.ru
Power saving policy: acpi_cpufreq + ondemand
$ select o.payment_method_id,pc.name,count(o.payment_method_id) as cnt from operation o
LEFT JOIN payment_method pm ON pm.id=o.payment_method_id
LEFT JOIN payment_classify pc ON pc.id = pm.payment_classify_id
WHERE (type='deposit')
AND (DATE(o.created)>='2015-04-05' AND DATE(o.created)<='2015-04-05') GROUP BY o.payment_method_id,pc.name
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=44.24..44.25 rows=1 width=26) (actual time=238.506..238.512 rows=20 loops=1)
-> Nested Loop Left Join (cost=0.01..44.23 rows=1 width=26) (actual time=0.068..232.756 rows=10660 loops=1)
-> Nested Loop Left Join (cost=0.01..43.64 rows=1 width=16) (actual time=0.058..206.598 rows=10660 loops=1)
Join Filter: (pm.id = o.payment_method_id)
Rows Removed by Join Filter: 394420
-> Index Scan using operation_date_created_type_state_key on operation o (cost=0.01..41.78 rows=1 width=8) (actual
time=0.042..109.343 rows=10660 loops=1)
Index Cond: ((date(created) >= '2015-04-05'::date) AND (date(created) <= '2015-04-05'::date) AND (type = 'deposit'::op_type))
-> Seq Scan on payment_method pm (cost=0.00..1.38 rows=38 width=12) (actual time=0.001..0.004 rows=38 loops=10660)
-> Index Scan using pc_pkey on payment_classify pc (cost=0.00..0.58 rows=1 width=22) (actual time=0.002..0.002 rows=1
loops=10660)
Index Cond: (id = pm.payment_classify_id)
Total runtime: 238.630 ms
26. Пенза, 24 апреля 2015
2015.secon.ru
Power saving policy: acpi_cpufreq + performance
$ select o.payment_method_id,pc.name,count(o.payment_method_id) as cnt from operation o
LEFT JOIN payment_method pm ON pm.id=o.payment_method_id
LEFT JOIN payment_classify pc ON pc.id = pm.payment_classify_id
WHERE (type='deposit')
AND (DATE(o.created)>='2015-04-05' AND DATE(o.created)<='2015-04-05') GROUP BY o.payment_method_id,pc.name
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=44.24..44.25 rows=1 width=26) (actual time=193.589..193.593 rows=20 loops=1)
-> Nested Loop Left Join (cost=0.01..44.23 rows=1 width=26) (actual time=0.034..188.948 rows=10660 loops=1)
-> Nested Loop Left Join (cost=0.01..43.64 rows=1 width=16) (actual time=0.030..166.176 rows=10660 loops=1)
Join Filter: (pm.id = o.payment_method_id)
Rows Removed by Join Filter: 394420
-> Index Scan using operation_date_created_type_state_key on operation o (cost=0.01..41.78 rows=1 width=8) (actual
time=0.022..87.541 rows=10660 loops=1)
Index Cond: ((date(created) >= '2015-04-05'::date) AND (date(created) <= '2015-04-05'::date) AND (type = 'deposit'::op_type))
-> Seq Scan on payment_method pm (cost=0.00..1.38 rows=38 width=12) (actual time=0.001..0.003 rows=38 loops=10660)
-> Index Scan using pc_pkey on payment_classify pc (cost=0.00..0.58 rows=1 width=22) (actual time=0.002..0.002 rows=1
loops=10660)
Index Cond: (id = pm.payment_classify_id)
Total runtime: 193.659 ms
27. Пенза, 24 апреля 2015
2015.secon.ru
Tuning target: Misc
● Clocksource
● acpi_pm vs. hpet vs. tsc
●
/sys/devices/system/clocksource/clocksource0/available_clocksource
●
/sys/devices/system/clocksource/clocksource0/current_clocksource
28. Пенза, 24 апреля 2015
2015.secon.ru
Clocksource: TSC
$ select o.payment_method_id,pc.name,count(o.payment_method_id) as cnt from operation o
LEFT JOIN payment_method pm ON pm.id=o.payment_method_id
LEFT JOIN payment_classify pc ON pc.id = pm.payment_classify_id
WHERE (type='deposit')
AND (DATE(o.created)>='2015-04-05' AND DATE(o.created)<='2015-04-05') GROUP BY o.payment_method_id,pc.name
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=44.24..44.25 rows=1 width=26) (actual time=244.300..244.308 rows=20 loops=1)
-> Nested Loop Left Join (cost=0.01..44.23 rows=1 width=26) (actual time=0.075..238.265 rows=10660 loops=1)
-> Nested Loop Left Join (cost=0.01..43.64 rows=1 width=16) (actual time=0.064..211.236 rows=10660 loops=1)
Join Filter: (pm.id = o.payment_method_id)
Rows Removed by Join Filter: 394420
-> Index Scan using operation_date_created_type_state_key on operation o (cost=0.01..41.79 rows=1 width=8) (actual
time=0.046..111.409 rows=10660 loops=1)
Index Cond: ((date(created) >= '2015-04-05'::date) AND (date(created) <= '2015-04-05'::date) AND (type = 'deposit'::op_type))
-> Seq Scan on payment_method pm (cost=0.00..1.38 rows=38 width=12) (actual time=0.001..0.004 rows=38 loops=10660)
-> Index Scan using pc_pkey on payment_classify pc (cost=0.00..0.58 rows=1 width=22) (actual time=0.002..0.002 rows=1
loops=10660)
Index Cond: (id = pm.payment_classify_id)
Total runtime: 244.433 ms
29. Пенза, 24 апреля 2015
2015.secon.ru
Clocksource: ACPI_PM
$ select o.payment_method_id,pc.name,count(o.payment_method_id) as cnt from operation o
LEFT JOIN payment_method pm ON pm.id=o.payment_method_id
LEFT JOIN payment_classify pc ON pc.id = pm.payment_classify_id
WHERE (type='deposit')
AND (DATE(o.created)>='2015-04-05' AND DATE(o.created)<='2015-04-05') GROUP BY o.payment_method_id,pc.name
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=44.24..44.25 rows=1 width=26) (actual time=1062.165..1062.188 rows=20 loops=1)
-> Nested Loop Left Join (cost=0.01..44.23 rows=1 width=26) (actual time=0.104..1047.211 rows=10660 loops=1)
-> Nested Loop Left Join (cost=0.01..43.64 rows=1 width=16) (actual time=0.091..962.252 rows=10660 loops=1)
Join Filter: (pm.id = o.payment_method_id)
Rows Removed by Join Filter: 394420
-> Index Scan using operation_date_created_type_state_key on operation o (cost=0.01..41.79 rows=1 width=8) (actual
time=0.046..104.546 rows=10660 loops=1)
Index Cond: ((date(created) >= '2015-04-05'::date) AND (date(created) <= '2015-04-05'::date) AND (type = 'deposit'::op_type))
-> Seq Scan on payment_method pm (cost=0.00..1.38 rows=38 width=12) (actual time=0.002..0.039 rows=38 loops=10660)
-> Index Scan using pc_pkey on payment_classify pc (cost=0.00..0.58 rows=1 width=22) (actual time=0.003..0.004 rows=1
loops=10660)
Index Cond: (id = pm.payment_classify_id)
Total runtime: 1062.316 ms