168 lines
18 KiB
Markdown
168 lines
18 KiB
Markdown
# Нагрузочный замер: метка `unit-of-work-before`
|
||
|
||
- Статус: **complete**
|
||
- Commit: `b2fb88f`
|
||
- Профиль `quick`: размеры 1k, 5k, 10k; клиенты 1, 4, 16; повторов 1; чтение 5 с после 2 с прогрева; запись 1000 после 100
|
||
- Лимиты без swap: API 1 CPU / 2g × 1 реплик за HAProxy 1 CPU / 256m, PostgreSQL 4 CPU / 3g, Valkey 2 CPU / 512m; CPU и RSS API — сумма по репликам; значения — медиана (min–max) по повторам
|
||
- Посторонние контейнеры в VM во время замера: domains-api-1, domains-bot-1, domains-postgres-1
|
||
|
||
## Сценарий `read`
|
||
|
||
| Размер | Клиенты | RPS | p50, мс | p95, мс | p99, мс | max, мс | CPU API, ядер | CPU БД, ядер | RSS конец, МиБ | Сообщений в начале | Пометки |
|
||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1k | 1 | 498 | 1.86 | 2.46 | 2.95 | 3.9 | 0.82 | 0.14 | 125.0 | 4500 | — |
|
||
| 1k | 4 | 659 | 5.21 | 8.53 | 18.93 | 62.8 | 1.00 | 0.18 | 125.0 | 4500 | — |
|
||
| 1k | 16 | 700 | 20.99 | 39.75 | 61.91 | 85.9 | 1.00 | 0.18 | 125.0 | 4500 | — |
|
||
| 5k | 1 | 445 | 1.95 | 3.00 | 4.12 | 80.8 | 0.82 | 0.14 | 125.0 | 8500 | — |
|
||
| 5k | 4 | 656 | 5.42 | 8.59 | 15.03 | 44.2 | 1.00 | 0.19 | 125.0 | 8500 | — |
|
||
| 5k | 16 | 605 | 23.79 | 50.61 | 76.91 | 128.5 | 1.01 | 0.20 | 125.0 | 8500 | — |
|
||
| 10k | 1 | 451 | 1.85 | 3.16 | 6.16 | 49.0 | 0.81 | 0.15 | 125.1 | 13500 | — |
|
||
| 10k | 4 | 632 | 5.64 | 8.47 | 14.29 | 55.6 | 1.00 | 0.19 | 125.1 | 13500 | — |
|
||
| 10k | 16 | 608 | 22.06 | 56.76 | 79.45 | 216.9 | 1.00 | 0.19 | 125.2 | 13500 | — |
|
||
|
||
## Сценарий `write`
|
||
|
||
| Размер | Клиенты | RPS | p50, мс | p95, мс | p99, мс | max, мс | CPU API, ядер | CPU БД, ядер | RSS конец, МиБ | Сообщений в начале | Пометки |
|
||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1k | 1 | 407 | 2.05 | 3.85 | 5.66 | 14.7 | 0.76 | 0.13 | 125.0 | 4600 | — |
|
||
| 1k | 4 | 612 | 5.68 | 10.72 | 12.30 | 15.9 | 0.99 | 0.22 | 125.0 | 5700 | — |
|
||
| 1k | 16 | 598 | 25.08 | 40.42 | 77.29 | 85.2 | 1.01 | 0.22 | 125.2 | 6800 | — |
|
||
| 5k | 1 | 398 | 2.07 | 3.96 | 7.61 | 25.0 | 0.76 | 0.16 | 125.0 | 8600 | — |
|
||
| 5k | 4 | 584 | 6.08 | 8.98 | 15.05 | 80.7 | 1.00 | 0.19 | 125.0 | 9700 | — |
|
||
| 5k | 16 | 383 | 32.16 | 95.92 | 125.39 | 159.2 | 1.00 | 0.27 | 125.4 | 10800 | — |
|
||
| 10k | 1 | 495 | 1.89 | 2.34 | 3.11 | 7.8 | 0.78 | 0.14 | 125.2 | 13600 | — |
|
||
| 10k | 4 | 629 | 5.79 | 8.02 | 9.85 | 69.2 | 0.99 | 0.19 | 125.2 | 14700 | — |
|
||
| 10k | 16 | 526 | 27.19 | 56.24 | 87.51 | 110.4 | 1.01 | 0.23 | 125.5 | 15800 | — |
|
||
|
||
## Память и наполнение по размерам
|
||
|
||
Объём `messages` — после `VACUUM (ANALYZE)`, до прогонов: в таблице N сообщений читаемого чата и сообщения фоновых чатов (`Сообщений`).
|
||
|
||
| Размер | Сообщений | RSS API до, МиБ | RSS API после, МиБ | Байт RSS на сообщение | Таблица, МиБ | Индексы, МиБ | Байт в БД на сообщение | Наполнение, сообщ/с | Курсоров в пуле | Пик RSS за размер, МиБ |
|
||
|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1k | 4500 | 121.1 | 124.9 | 895 | 0.8 | 0.6 | 328 | 554 | 9 | 184.6 |
|
||
| 5k | 8500 | 121.1 | 124.9 | 473 | 1.5 | 1.1 | 318 | 512 | 49 | 184.5 |
|
||
| 10k | 13500 | 121.1 | 125.1 | 313 | 2.3 | 1.9 | 329 | 515 | 99 | 184.5 |
|
||
|
||
## Планы запроса истории
|
||
|
||
Страница (`limit` профиля) читаемого чата и первого чата каждого фонового уровня. `app` — план запроса приложения (auto_explain). Остальное — тот же запрос с теми же параметрами в psql, в откатываемой транзакции: `psql` — индекс приложения, `generic` — он же с generic plan, `or-cursor` — условие курсора через OR, `no-index` — без индекса, дальше — варианты индекса профиля. Буферы — верхнего узла плана, файлы — `explain-<размер>.txt`.
|
||
|
||
| Размер | Чат | Страница | После сообщений | Вариант | Узел | shared hit | read | Строк | Время, мс | План |
|
||
|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1k | read 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 38 | 0 | 51 | 0.112 | custom |
|
||
| 1k | read 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 52 | 0 | 51 | 0.109 | custom |
|
||
| 1k | read 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 52 | 0 | 51 | 0.067 | custom |
|
||
| 1k | read 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 52 | 0 | 51 | 0.079 | generic |
|
||
| 1k | read 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 533 | 0 | 51 | 0.132 | custom |
|
||
| 1k | read 1k | middle | 500 | no-index | Seq Scan on messages | 100 | 0 | 51 | 0.582 | custom |
|
||
| 1k | read 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 103 | 0 | 51 | 0.503 | custom |
|
||
| 1k | read 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.051 | custom |
|
||
| 1k | read 1k | last | 900 | app | Bitmap Heap Scan on messages | 27 | 0 | 51 | 0.190 | custom |
|
||
| 1k | bg 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 43 | 0 | 51 | 0.097 | custom |
|
||
| 1k | bg 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.096 | custom |
|
||
| 1k | bg 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.072 | custom |
|
||
| 1k | bg 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.063 | generic |
|
||
| 1k | bg 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 540 | 0 | 51 | 0.121 | custom |
|
||
| 1k | bg 1k | middle | 500 | no-index | Seq Scan on messages | 100 | 0 | 51 | 0.497 | custom |
|
||
| 1k | bg 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 103 | 0 | 51 | 0.446 | custom |
|
||
| 1k | bg 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.052 | custom |
|
||
| 1k | bg 1k | last | 900 | app | Bitmap Heap Scan on messages | 19 | 0 | 51 | 0.145 | custom |
|
||
| 1k | bg 100 | first | 0 | app | Bitmap Heap Scan on messages | 73 | 0 | 51 | 0.197 | custom |
|
||
| 1k | bg 100 | first | 0 | psql | Bitmap Heap Scan on messages | 73 | 0 | 51 | 0.136 | custom |
|
||
| 1k | bg 100 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.057 | generic |
|
||
| 1k | bg 100 | first | 0 | no-index | Seq Scan on messages | 100 | 0 | 51 | 0.206 | custom |
|
||
| 1k | bg 100 | first | 0 | chat_only | Bitmap Heap Scan on messages | 72 | 0 | 51 | 0.119 | custom |
|
||
| 1k | bg 100 | first | 0 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.047 | custom |
|
||
| 1k | bg 10 | first | 0 | app | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.036 | custom |
|
||
| 1k | bg 10 | first | 0 | psql | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.031 | custom |
|
||
| 1k | bg 10 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.026 | generic |
|
||
| 1k | bg 10 | first | 0 | no-index | Seq Scan on messages | 100 | 0 | 10 | 0.132 | custom |
|
||
| 1k | bg 10 | first | 0 | chat_only | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.030 | custom |
|
||
| 1k | bg 10 | first | 0 | covering | Index Only Scan using bench_variant on messages | 3 | 0 | 10 | 0.018 | custom |
|
||
| 5k | read 5k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 27 | 0 | 51 | 0.135 | custom |
|
||
| 5k | read 5k | middle | 2500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.130 | generic |
|
||
| 5k | read 5k | middle | 2500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.063 | custom |
|
||
| 5k | read 5k | middle | 2500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.064 | generic |
|
||
| 5k | read 5k | middle | 2500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 2555 | 0 | 51 | 0.402 | custom |
|
||
| 5k | read 5k | middle | 2500 | no-index | Seq Scan on messages | 186 | 0 | 51 | 2.243 | custom |
|
||
| 5k | read 5k | middle | 2500 | chat_only | Seq Scan on messages | 186 | 0 | 51 | 2.017 | custom |
|
||
| 5k | read 5k | middle | 2500 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.047 | custom |
|
||
| 5k | read 5k | last | 4900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.119 | generic |
|
||
| 5k | bg 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.118 | custom |
|
||
| 5k | bg 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 49 | 0 | 51 | 0.122 | generic |
|
||
| 5k | bg 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 49 | 0 | 51 | 0.059 | custom |
|
||
| 5k | bg 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 49 | 0 | 51 | 0.075 | generic |
|
||
| 5k | bg 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 531 | 0 | 51 | 0.134 | custom |
|
||
| 5k | bg 1k | middle | 500 | no-index | Seq Scan on messages | 186 | 0 | 51 | 0.569 | custom |
|
||
| 5k | bg 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 187 | 0 | 51 | 0.467 | custom |
|
||
| 5k | bg 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.055 | custom |
|
||
| 5k | bg 1k | last | 900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.136 | generic |
|
||
| 5k | bg 100 | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.168 | custom |
|
||
| 5k | bg 100 | first | 0 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.080 | custom |
|
||
| 5k | bg 100 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.094 | generic |
|
||
| 5k | bg 100 | first | 0 | no-index | Seq Scan on messages | 186 | 0 | 51 | 0.362 | custom |
|
||
| 5k | bg 100 | first | 0 | chat_only | Bitmap Heap Scan on messages | 83 | 0 | 51 | 0.149 | custom |
|
||
| 5k | bg 100 | first | 0 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.053 | custom |
|
||
| 5k | bg 10 | first | 0 | app | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.088 | custom |
|
||
| 5k | bg 10 | first | 0 | psql | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.049 | custom |
|
||
| 5k | bg 10 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.029 | generic |
|
||
| 5k | bg 10 | first | 0 | no-index | Seq Scan on messages | 186 | 0 | 10 | 0.205 | custom |
|
||
| 5k | bg 10 | first | 0 | chat_only | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.026 | custom |
|
||
| 5k | bg 10 | first | 0 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 10 | 0.020 | custom |
|
||
| 10k | read 10k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 18 | 0 | 51 | 0.166 | custom |
|
||
| 10k | read 10k | middle | 5000 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.159 | generic |
|
||
| 10k | read 10k | middle | 5000 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.056 | custom |
|
||
| 10k | read 10k | middle | 5000 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.069 | generic |
|
||
| 10k | read 10k | middle | 5000 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 5077 | 0 | 51 | 0.621 | custom |
|
||
| 10k | read 10k | middle | 5000 | no-index | Seq Scan on messages | 294 | 0 | 51 | 3.760 | custom |
|
||
| 10k | read 10k | middle | 5000 | chat_only | Seq Scan on messages | 294 | 0 | 51 | 3.726 | custom |
|
||
| 10k | read 10k | middle | 5000 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.051 | custom |
|
||
| 10k | read 10k | last | 9900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 54 | 0 | 51 | 0.111 | generic |
|
||
| 10k | bg 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.147 | custom |
|
||
| 10k | bg 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 46 | 0 | 51 | 0.129 | generic |
|
||
| 10k | bg 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 46 | 0 | 51 | 0.054 | custom |
|
||
| 10k | bg 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 46 | 0 | 51 | 0.066 | generic |
|
||
| 10k | bg 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 507 | 0 | 51 | 0.141 | custom |
|
||
| 10k | bg 1k | middle | 500 | no-index | Seq Scan on messages | 294 | 0 | 51 | 1.061 | custom |
|
||
| 10k | bg 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 286 | 0 | 51 | 0.467 | custom |
|
||
| 10k | bg 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.051 | custom |
|
||
| 10k | bg 1k | last | 900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.131 | generic |
|
||
| 10k | bg 100 | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.157 | custom |
|
||
| 10k | bg 100 | first | 0 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.060 | custom |
|
||
| 10k | bg 100 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.072 | generic |
|
||
| 10k | bg 100 | first | 0 | no-index | Seq Scan on messages | 294 | 0 | 51 | 0.415 | custom |
|
||
| 10k | bg 100 | first | 0 | chat_only | Bitmap Heap Scan on messages | 95 | 0 | 51 | 0.131 | custom |
|
||
| 10k | bg 100 | first | 0 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.051 | custom |
|
||
| 10k | bg 10 | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.043 | custom |
|
||
| 10k | bg 10 | first | 0 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.022 | custom |
|
||
| 10k | bg 10 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.026 | generic |
|
||
| 10k | bg 10 | first | 0 | no-index | Seq Scan on messages | 294 | 0 | 10 | 0.358 | custom |
|
||
| 10k | bg 10 | first | 0 | chat_only | Index Scan using bench_variant on messages | 12 | 0 | 10 | 0.023 | custom |
|
||
| 10k | bg 10 | first | 0 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 10 | 0.019 | custom |
|
||
|
||
## Стоимость записи по вариантам индекса
|
||
|
||
Вставка порции сообщений во все чаты в пропорции наполнения одной командой, в транзакции, которая откатывается; индекс истории построен заново, перед вставкой `CHECKPOINT`. Значения — медиана (min–max) повторов. «4000 символов» — вставка сообщения максимальной длины из несжимаемого текста.
|
||
|
||
| Размер | Вариант | Строк вставки | Индекс, МиБ | Байт индекса на сообщение | мкс на сообщение | WAL байт на сообщение | FPI на 1000 | 4000 символов |
|
||
|---|---|---|---|---|---|---|---|---|
|
||
| 1k | app | 5000 | 0.5 | 60.9 | 5.57 (4.92–5.86) | 487 (487–499) | 20.2 (11.2–20.2) | ok |
|
||
| 1k | chat_only | 5000 | 0.1 | 10.5 | 4.77 (4.73–5.09) | 399 (399–399) | 18.0 (18.0–18.0) | ok |
|
||
| 1k | covering | 5000 | 1.2 | 159.6 | 5.36 (5.30–6.96) | 693 (693–693) | 24.2 (24.2–24.2) | index row requires 12072 bytes, maximum size is 8191 |
|
||
| 1k | none | 5000 | 0.0 | 0.0 | 4.29 (4.26–4.37) | 314 (314–314) | 16.6 (16.6–16.6) | ok |
|
||
| 5k | app | 5000 | 0.7 | 60.4 | 5.05 (4.93–6.68) | 506 (500–506) | 21.8 (17.8–21.8) | ok |
|
||
| 5k | chat_only | 5000 | 0.1 | 9.0 | 4.76 (4.70–4.76) | 421 (421–422) | 19.2 (19.2–19.6) | ok |
|
||
| 5k | covering | 5000 | 1.8 | 160.4 | 5.81 (5.45–5.87) | 703 (703–703) | 25.0 (25.0–25.2) | index row requires 12072 bytes, maximum size is 8191 |
|
||
| 5k | none | 5000 | 0.0 | 0.0 | 4.27 (4.25–4.70) | 336 (336–336) | 17.8 (17.6–17.8) | ok |
|
||
| 10k | app | 5000 | 1.0 | 59.5 | 5.12 (5.01–6.31) | 542 (540–557) | 31.4 (19.0–31.6) | ok |
|
||
| 10k | chat_only | 5000 | 0.1 | 8.3 | 4.80 (4.72–5.69) | 452 (450–454) | 29.2 (27.6–29.4) | ok |
|
||
| 10k | covering | 5000 | 2.6 | 160.4 | 5.59 (5.47–7.14) | 748 (748–749) | 35.4 (34.8–35.4) | index row requires 12072 bytes, maximum size is 8191 |
|
||
| 10k | none | 5000 | 0.0 | 0.0 | 4.36 (4.34–4.45) | 365 (365–367) | 27.8 (27.4–27.8) | ok |
|
||
|
||
## Кривая наполнения 10k: запись при росте хранилища, 32 клиента
|
||
|
||
| Порция | Сообщений после | RPS | p50, мс | p95, мс | p99, мс | max, мс | CPU API, ядер | CPU БД, ядер | RSS, МиБ | Пометки |
|
||
|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1 | 13500 | 515 | 56.009 | 121.243 | 188.234 | 417.242 | 0.996 | 0.22 | 125.1 | — |
|