Skip to content

Commit cbcbac8

Browse files
vgvolegblinkov
andauthored
Python SDK topic autoscaling docs (#14583)
Co-authored-by: Ivan Blinkov <ivan@ydb.tech>
1 parent 4d951ba commit cbcbac8

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

ydb/docs/en/core/reference/ydb-sdk/topic.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,3 +1951,62 @@ In case of a _hard interruption_, the client receives a notification that it is
19511951
```
19521952

19531953
{% endlist %}
1954+
1955+
### Topic autoscaling {#autoscaling}
1956+
1957+
{% list tabs group=lang %}
1958+
1959+
- Python
1960+
1961+
Autoscaling of a topic can be enabled during its creation using the `auto_partitioning_settings` argument of `create_topic`:
1962+
1963+
```python
1964+
driver.topic_client.create_topic(
1965+
topic,
1966+
consumers=[consumer],
1967+
min_active_partitions=10,
1968+
max_active_partitions=100,
1969+
auto_partitioning_settings=ydb.TopicAutoPartitioningSettings(
1970+
strategy=ydb.TopicAutoPartitioningStrategy.SCALE_UP,
1971+
up_utilization_percent=80,
1972+
down_utilization_percent=20,
1973+
stabilization_window=datetime.timedelta(seconds=300),
1974+
),
1975+
)
1976+
```
1977+
1978+
Changes to an existing topic can be made using the `alter_auto_partitioning_settings` argument of `alter_topic`:
1979+
1980+
```python
1981+
driver.topic_client.alter_topic(
1982+
topic_path,
1983+
alter_auto_partitioning_settings=ydb.TopicAlterAutoPartitioningSettings(
1984+
set_strategy=ydb.TopicAutoPartitioningStrategy.SCALE_UP,
1985+
set_up_utilization_percent=80,
1986+
set_down_utilization_percent=20,
1987+
set_stabilization_window=datetime.timedelta(seconds=300),
1988+
),
1989+
)
1990+
```
1991+
1992+
The SDK supports two topic reading modes with autoscaling enabled: full support mode and compatibility mode. The reading mode can be set in the `auto_partitioning_support` argument when creating the reader. Full support mode is used by default.
1993+
1994+
```python
1995+
reader = driver.topic_client.reader(
1996+
topic,
1997+
consumer,
1998+
auto_partitioning_support=True, # Full support is enabled
1999+
)
2000+
2001+
# or
2002+
2003+
reader = driver.topic_client.reader(
2004+
topic,
2005+
consumer,
2006+
auto_partitioning_support=False, # Compatibility mode is enabled
2007+
)
2008+
```
2009+
2010+
From a practical perspective, these modes do not differ for the end user. However, the full support mode differs from the compatibility mode in terms of who guarantees the order of reading—the client or the server. Compatibility mode is achieved through server-side processing and generally operates slower.
2011+
2012+
{% endlist %}

ydb/docs/ru/core/reference/ydb-sdk/topic.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,4 +1999,57 @@
19991999
20002000
Рекомендуется проверять корректность обработки мягкого прерывания чтения: клиент должен обработать полученные сообщения, подтвердить их обработку (коммит) или сохранить позицию чтения в своей базе, и только после этого вызывать `Confirm()` для события `TStopPartitionSessionEvent`.
20012001
2002+
- Python
2003+
2004+
Включение автомасштабирования топика во время его создания производится с помощью аргумента `auto_partitioning_settings` у `create_topic`:
2005+
2006+
```python
2007+
driver.topic_client.create_topic(
2008+
topic,
2009+
consumers=[consumer],
2010+
min_active_partitions=10,
2011+
max_active_partitions=100,
2012+
auto_partitioning_settings=ydb.TopicAutoPartitioningSettings(
2013+
strategy=ydb.TopicAutoPartitioningStrategy.SCALE_UP,
2014+
up_utilization_percent=80,
2015+
down_utilization_percent=20,
2016+
stabilization_window=datetime.timedelta(seconds=300),
2017+
),
2018+
)
2019+
```
2020+
2021+
Внесение изменений в существующий топик производится с помощью аргумента `alter_auto_partitioning_settings` у `alter_topic`:
2022+
2023+
```python
2024+
driver.topic_client.alter_topic(
2025+
topic_path,
2026+
alter_auto_partitioning_settings=ydb.TopicAlterAutoPartitioningSettings(
2027+
set_strategy=ydb.TopicAutoPartitioningStrategy.SCALE_UP,
2028+
set_up_utilization_percent=80,
2029+
set_down_utilization_percent=20,
2030+
set_stabilization_window=datetime.timedelta(seconds=300),
2031+
),
2032+
)
2033+
```
2034+
2035+
SDK поддерживает два режима чтения топиков с включенным автомасштабированием: режим полной поддержки и режим совместимости. Режим чтения задаётся аргументом `auto_partitioning_support` во время создания читателя. По умолчанию используется режим полной поддержки.
2036+
2037+
```python
2038+
reader = driver.topic_client.reader(
2039+
topic,
2040+
consumer,
2041+
auto_partitioning_support=True, # Full support is enabled
2042+
)
2043+
2044+
# or
2045+
2046+
reader = driver.topic_client.reader(
2047+
topic,
2048+
consumer,
2049+
auto_partitioning_support=False, # Compatibility mode is enabled
2050+
)
2051+
```
2052+
2053+
С практической точки зрения для конечного пользователя режимы не отличаются. Режим полной поддержки отличается от режима совместимости тем, кто гарантирует порядок чтения — клиент или сервер. Режим совместимости достигается серверной обработкой и, как правило, работает медленнее.
2054+
20022055
{% endlist %}

0 commit comments

Comments
 (0)