168 lines
18 KiB
Markdown
168 lines
18 KiB
Markdown
# Нагрузочный замер: метка `unit-of-work-after`
|
||
|
||
- Статус: **complete**
|
||
- Commit: `6ba74b1`
|
||
- Профиль `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 | 417 | 2.22 | 2.92 | 3.76 | 12.8 | 0.76 | 0.12 | 127.6 | 4500 | — |
|
||
| 1k | 4 | 618 | 6.08 | 7.63 | 10.92 | 47.5 | 0.99 | 0.17 | 127.6 | 4500 | — |
|
||
| 1k | 16 | 568 | 26.01 | 56.30 | 66.86 | 73.3 | 1.00 | 0.17 | 127.6 | 4500 | — |
|
||
| 5k | 1 | 431 | 2.16 | 2.79 | 3.46 | 8.1 | 0.76 | 0.12 | 127.7 | 8500 | — |
|
||
| 5k | 4 | 615 | 5.97 | 7.60 | 13.78 | 54.1 | 0.99 | 0.18 | 127.7 | 8500 | — |
|
||
| 5k | 16 | 565 | 25.44 | 56.14 | 67.89 | 78.2 | 1.00 | 0.17 | 127.7 | 8500 | — |
|
||
| 10k | 1 | 417 | 2.22 | 2.96 | 4.16 | 9.4 | 0.75 | 0.12 | 127.7 | 13500 | — |
|
||
| 10k | 4 | 596 | 6.01 | 8.84 | 16.64 | 53.9 | 0.99 | 0.18 | 127.7 | 13500 | — |
|
||
| 10k | 16 | 566 | 26.08 | 54.08 | 63.84 | 71.1 | 1.00 | 0.17 | 127.7 | 13500 | — |
|
||
|
||
## Сценарий `write`
|
||
|
||
| Размер | Клиенты | RPS | p50, мс | p95, мс | p99, мс | max, мс | CPU API, ядер | CPU БД, ядер | RSS конец, МиБ | Сообщений в начале | Пометки |
|
||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1k | 1 | 376 | 2.40 | 3.63 | 5.18 | 14.0 | 0.76 | 0.13 | 127.6 | 4600 | — |
|
||
| 1k | 4 | 585 | 6.51 | 7.79 | 10.01 | 45.3 | 0.98 | 0.18 | 127.6 | 5700 | — |
|
||
| 1k | 16 | 518 | 28.68 | 42.58 | 77.10 | 83.8 | 1.01 | 0.20 | 127.6 | 6800 | — |
|
||
| 5k | 1 | 400 | 2.33 | 3.11 | 4.17 | 6.7 | 0.76 | 0.14 | 127.7 | 8600 | — |
|
||
| 5k | 4 | 566 | 6.54 | 9.23 | 13.66 | 47.1 | 0.98 | 0.20 | 127.7 | 9700 | — |
|
||
| 5k | 16 | 527 | 27.81 | 44.96 | 74.63 | 81.5 | 1.01 | 0.20 | 127.7 | 10800 | — |
|
||
| 10k | 1 | 378 | 2.41 | 3.45 | 4.91 | 11.7 | 0.75 | 0.13 | 127.7 | 13600 | — |
|
||
| 10k | 4 | 546 | 6.72 | 9.69 | 12.87 | 49.5 | 1.00 | 0.19 | 127.7 | 14700 | — |
|
||
| 10k | 16 | 515 | 29.18 | 44.99 | 66.27 | 69.5 | 1.01 | 0.22 | 127.7 | 15800 | — |
|
||
|
||
## Память и наполнение по размерам
|
||
|
||
Объём `messages` — после `VACUUM (ANALYZE)`, до прогонов: в таблице N сообщений читаемого чата и сообщения фоновых чатов (`Сообщений`).
|
||
|
||
| Размер | Сообщений | RSS API до, МиБ | RSS API после, МиБ | Байт RSS на сообщение | Таблица, МиБ | Индексы, МиБ | Байт в БД на сообщение | Наполнение, сообщ/с | Курсоров в пуле | Пик RSS за размер, МиБ |
|
||
|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1k | 4500 | 121.4 | 127.6 | 1430 | 0.8 | 0.6 | 330 | 488 | 9 | 185.0 |
|
||
| 5k | 8500 | 121.5 | 127.6 | 758 | 1.5 | 1.1 | 321 | 492 | 49 | 185.0 |
|
||
| 10k | 13500 | 121.5 | 127.6 | 478 | 2.3 | 1.9 | 328 | 497 | 99 | 185.0 |
|
||
|
||
## Планы запроса истории
|
||
|
||
Страница (`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 | 27 | 0 | 51 | 0.156 | custom |
|
||
| 1k | read 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.160 | custom |
|
||
| 1k | read 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.070 | custom |
|
||
| 1k | read 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.069 | generic |
|
||
| 1k | read 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 496 | 0 | 51 | 0.128 | custom |
|
||
| 1k | read 1k | middle | 500 | no-index | Seq Scan on messages | 101 | 0 | 51 | 0.578 | custom |
|
||
| 1k | read 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 103 | 0 | 51 | 0.466 | custom |
|
||
| 1k | read 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.057 | custom |
|
||
| 1k | read 1k | last | 900 | app | Bitmap Heap Scan on messages | 22 | 0 | 51 | 0.279 | custom |
|
||
| 1k | bg 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 32 | 0 | 51 | 0.135 | custom |
|
||
| 1k | bg 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 49 | 0 | 51 | 0.108 | custom |
|
||
| 1k | bg 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 49 | 0 | 51 | 0.068 | custom |
|
||
| 1k | bg 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 49 | 0 | 51 | 0.069 | generic |
|
||
| 1k | bg 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 487 | 0 | 51 | 0.125 | custom |
|
||
| 1k | bg 1k | middle | 500 | no-index | Seq Scan on messages | 101 | 0 | 51 | 0.489 | custom |
|
||
| 1k | bg 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 101 | 0 | 51 | 0.431 | custom |
|
||
| 1k | bg 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.055 | custom |
|
||
| 1k | bg 1k | last | 900 | app | Bitmap Heap Scan on messages | 19 | 0 | 51 | 0.154 | custom |
|
||
| 1k | bg 100 | first | 0 | app | Bitmap Heap Scan on messages | 65 | 0 | 51 | 0.314 | custom |
|
||
| 1k | bg 100 | first | 0 | psql | Bitmap Heap Scan on messages | 65 | 0 | 51 | 0.138 | custom |
|
||
| 1k | bg 100 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 45 | 0 | 51 | 0.065 | generic |
|
||
| 1k | bg 100 | first | 0 | no-index | Seq Scan on messages | 101 | 0 | 51 | 0.198 | custom |
|
||
| 1k | bg 100 | first | 0 | chat_only | Bitmap Heap Scan on messages | 65 | 0 | 51 | 0.125 | custom |
|
||
| 1k | bg 100 | first | 0 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 51 | 0.049 | custom |
|
||
| 1k | bg 10 | first | 0 | app | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.043 | custom |
|
||
| 1k | bg 10 | first | 0 | psql | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.047 | custom |
|
||
| 1k | bg 10 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.029 | generic |
|
||
| 1k | bg 10 | first | 0 | no-index | Seq Scan on messages | 101 | 0 | 10 | 0.146 | custom |
|
||
| 1k | bg 10 | first | 0 | chat_only | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.033 | custom |
|
||
| 1k | bg 10 | first | 0 | covering | Index Only Scan using bench_variant on messages | 3 | 0 | 10 | 0.015 | custom |
|
||
| 5k | read 5k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 25 | 0 | 51 | 0.156 | custom |
|
||
| 5k | read 5k | middle | 2500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.178 | generic |
|
||
| 5k | read 5k | middle | 2500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.065 | custom |
|
||
| 5k | read 5k | middle | 2500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 53 | 0 | 51 | 0.077 | generic |
|
||
| 5k | read 5k | middle | 2500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 2365 | 0 | 51 | 0.380 | custom |
|
||
| 5k | read 5k | middle | 2500 | no-index | Seq Scan on messages | 184 | 0 | 51 | 2.122 | custom |
|
||
| 5k | read 5k | middle | 2500 | chat_only | Seq Scan on messages | 184 | 0 | 51 | 2.124 | custom |
|
||
| 5k | read 5k | middle | 2500 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.053 | custom |
|
||
| 5k | read 5k | last | 4900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 50 | 0 | 51 | 0.159 | generic |
|
||
| 5k | bg 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 42 | 0 | 51 | 0.113 | custom |
|
||
| 5k | bg 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 46 | 0 | 51 | 0.128 | generic |
|
||
| 5k | bg 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 46 | 0 | 51 | 0.064 | custom |
|
||
| 5k | bg 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 46 | 0 | 51 | 0.064 | generic |
|
||
| 5k | bg 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 498 | 0 | 51 | 0.114 | custom |
|
||
| 5k | bg 1k | middle | 500 | no-index | Seq Scan on messages | 184 | 0 | 51 | 0.568 | custom |
|
||
| 5k | bg 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 186 | 0 | 51 | 0.435 | custom |
|
||
| 5k | bg 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.053 | custom |
|
||
| 5k | bg 1k | last | 900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 50 | 0 | 51 | 0.108 | generic |
|
||
| 5k | bg 100 | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.172 | custom |
|
||
| 5k | bg 100 | first | 0 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.061 | custom |
|
||
| 5k | bg 100 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 51 | 0 | 51 | 0.063 | generic |
|
||
| 5k | bg 100 | first | 0 | no-index | Seq Scan on messages | 184 | 0 | 51 | 0.273 | custom |
|
||
| 5k | bg 100 | first | 0 | chat_only | Bitmap Heap Scan on messages | 84 | 0 | 51 | 0.129 | custom |
|
||
| 5k | bg 100 | first | 0 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.048 | custom |
|
||
| 5k | bg 10 | first | 0 | app | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.052 | custom |
|
||
| 5k | bg 10 | first | 0 | psql | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.030 | custom |
|
||
| 5k | bg 10 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.024 | generic |
|
||
| 5k | bg 10 | first | 0 | no-index | Seq Scan on messages | 184 | 0 | 10 | 0.202 | custom |
|
||
| 5k | bg 10 | first | 0 | chat_only | Bitmap Heap Scan on messages | 12 | 0 | 10 | 0.022 | custom |
|
||
| 5k | bg 10 | first | 0 | covering | Index Only Scan using bench_variant on messages | 4 | 0 | 10 | 0.019 | custom |
|
||
| 10k | read 10k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 10 | 0 | 51 | 0.183 | custom |
|
||
| 10k | read 10k | middle | 5000 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 50 | 0 | 51 | 0.173 | generic |
|
||
| 10k | read 10k | middle | 5000 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 50 | 0 | 51 | 0.063 | custom |
|
||
| 10k | read 10k | middle | 5000 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 50 | 0 | 51 | 0.065 | generic |
|
||
| 10k | read 10k | middle | 5000 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 4713 | 0 | 51 | 0.732 | custom |
|
||
| 10k | read 10k | middle | 5000 | no-index | Seq Scan on messages | 294 | 0 | 51 | 4.012 | custom |
|
||
| 10k | read 10k | middle | 5000 | chat_only | Seq Scan on messages | 294 | 0 | 51 | 3.763 | 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 | 48 | 0 | 51 | 0.165 | generic |
|
||
| 10k | bg 1k | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 48 | 0 | 51 | 0.150 | custom |
|
||
| 10k | bg 1k | middle | 500 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.174 | generic |
|
||
| 10k | bg 1k | middle | 500 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.056 | custom |
|
||
| 10k | bg 1k | middle | 500 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 47 | 0 | 51 | 0.061 | generic |
|
||
| 10k | bg 1k | middle | 500 | or-cursor | Index Scan using ix_messages_chat_id_created_at_id on messages | 514 | 0 | 51 | 0.125 | custom |
|
||
| 10k | bg 1k | middle | 500 | no-index | Seq Scan on messages | 294 | 0 | 51 | 0.708 | custom |
|
||
| 10k | bg 1k | middle | 500 | chat_only | Bitmap Heap Scan on messages | 285 | 0 | 51 | 0.484 | custom |
|
||
| 10k | bg 1k | middle | 500 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.055 | custom |
|
||
| 10k | bg 1k | last | 900 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 48 | 0 | 51 | 0.136 | generic |
|
||
| 10k | bg 100 | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 43 | 0 | 51 | 0.182 | custom |
|
||
| 10k | bg 100 | first | 0 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 43 | 0 | 51 | 0.063 | custom |
|
||
| 10k | bg 100 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 43 | 0 | 51 | 0.064 | generic |
|
||
| 10k | bg 100 | first | 0 | no-index | Seq Scan on messages | 294 | 0 | 51 | 0.403 | custom |
|
||
| 10k | bg 100 | first | 0 | chat_only | Bitmap Heap Scan on messages | 85 | 0 | 51 | 0.129 | custom |
|
||
| 10k | bg 100 | first | 0 | covering | Index Only Scan using bench_variant on messages | 5 | 0 | 51 | 0.055 | custom |
|
||
| 10k | bg 10 | first | 0 | app | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.086 | custom |
|
||
| 10k | bg 10 | first | 0 | psql | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.028 | custom |
|
||
| 10k | bg 10 | first | 0 | generic | Index Scan using ix_messages_chat_id_created_at_id on messages | 12 | 0 | 10 | 0.024 | generic |
|
||
| 10k | bg 10 | first | 0 | no-index | Seq Scan on messages | 294 | 0 | 10 | 0.329 | custom |
|
||
| 10k | bg 10 | first | 0 | chat_only | Index Scan using bench_variant on messages | 12 | 0 | 10 | 0.027 | 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.80 (5.07–5.86) | 490 (490–501) | 21.2 (12.0–21.2) | ok |
|
||
| 1k | chat_only | 5000 | 0.1 | 9.5 | 4.97 (4.89–5.17) | 402 (402–403) | 18.6 (18.6–18.6) | ok |
|
||
| 1k | covering | 5000 | 1.2 | 159.6 | 5.55 (5.38–6.05) | 695 (695–695) | 25.0 (25.0–25.0) | index row requires 12072 bytes, maximum size is 8191 |
|
||
| 1k | none | 5000 | 0.0 | 0.0 | 4.38 (4.35–4.38) | 314 (314–314) | 17.2 (17.2–17.2) | ok |
|
||
| 5k | app | 5000 | 0.7 | 60.4 | 5.91 (4.98–6.52) | 506 (501–506) | 22.0 (17.6–22.0) | ok |
|
||
| 5k | chat_only | 5000 | 0.1 | 9.0 | 5.02 (4.87–5.05) | 423 (422–424) | 19.8 (19.2–19.8) | ok |
|
||
| 5k | covering | 5000 | 1.8 | 160.4 | 5.61 (5.55–5.77) | 711 (711–712) | 25.6 (25.4–25.6) | index row requires 12072 bytes, maximum size is 8191 |
|
||
| 5k | none | 5000 | 0.0 | 0.0 | 4.32 (4.26–4.35) | 334 (334–334) | 18.2 (18.0–18.2) | ok |
|
||
| 10k | app | 5000 | 1.0 | 59.5 | 5.21 (5.11–7.05) | 543 (543–556) | 31.2 (19.2–31.2) | ok |
|
||
| 10k | chat_only | 5000 | 0.1 | 8.3 | 4.83 (4.80–4.90) | 454 (454–458) | 28.8 (27.6–29.0) | ok |
|
||
| 10k | covering | 5000 | 2.6 | 160.4 | 5.72 (5.64–5.88) | 754 (753–755) | 35.6 (35.0–35.6) | index row requires 12072 bytes, maximum size is 8191 |
|
||
| 10k | none | 5000 | 0.0 | 0.0 | 4.42 (4.34–4.79) | 368 (368–370) | 27.6 (27.4–27.6) | ok |
|
||
|
||
## Кривая наполнения 10k: запись при росте хранилища, 32 клиента
|
||
|
||
| Порция | Сообщений после | RPS | p50, мс | p95, мс | p99, мс | max, мс | CPU API, ядер | CPU БД, ядер | RSS, МиБ | Пометки |
|
||
|---|---|---|---|---|---|---|---|---|---|---|
|
||
| 1 | 13500 | 496 | 56.805 | 132.984 | 180.953 | 321.418 | 0.999 | 0.189 | 127.6 | — |
|