diff --git a/docs/examples/python/highvolume_example.py b/docs/examples/python/highvolume_example.py index 8c964395a428fca71bb9b26fa0cbf91f803a8377..6d4f9185cea9f964405e6b3795d6057eb8b03022 100644 --- a/docs/examples/python/highvolume_example.py +++ b/docs/examples/python/highvolume_example.py @@ -47,16 +47,12 @@ class DataBaseMonitor: return int(r[1]) def stat_and_print(self): - try: - last_count = 0 - while True: - time.sleep(10) - count = self.get_count() - logging.info(f"count={count} speed={(count - last_count) / 10}") - last_count = count - except KeyboardInterrupt: - [p.terminate() for p in read_processes] - [p.terminate() for p in write_processes] + last_count = 0 + while True: + time.sleep(10) + count = self.get_count() + logging.info(f"count={count} speed={(count - last_count) / 10}") + last_count = count # ANCHOR_END: DataBaseMonitor @@ -154,6 +150,7 @@ class SQLWriter: self._buffered_count = 0 def execute_sql(self, sql): + self.log.debug(sql) try: self._conn.execute(sql) except taos.Error as e: @@ -258,7 +255,12 @@ def main(): p.start() read_processes.append(p) - database_monitor.stat_and_print() + try: + database_monitor.stat_and_print() + except KeyboardInterrupt: + [p.terminate() for p in read_processes] + [p.terminate() for p in write_processes] + exit() # ANCHOR_END: main diff --git a/docs/zh/07-develop/03-insert-data/05-high-volume.md b/docs/zh/07-develop/03-insert-data/05-high-volume.md index aafe9aec3a6a92de4fdc4cd199e4ea81f9fde5b5..69b30eb02b3f7e9582523ed95841dbeb0179eb22 100644 --- a/docs/zh/07-develop/03-insert-data/05-high-volume.md +++ b/docs/zh/07-develop/03-insert-data/05-high-volume.md @@ -39,9 +39,13 @@ title: 高效写入 3. 模拟生成的总表数。默认为 1000。将会平分给各个读线程。 4. 每批最大数据量。默认为 3000。 -```java title="主程序" +
+主程序 +```java {{#include docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java:main}} ``` +
+ 队列容量(taskQueueCapacity)也是与性能有关的参数,可通过修改程序调节。一般来讲,队列容量越大,入队被阻塞的概率越小,队列的吞吐量越大,但是内存占用也会越大。 @@ -163,8 +167,78 @@ TDENGINE_JDBC_URL="jdbc:TAOS://localhost:6030?user=root&password=taosdata" ## Python 示例程序 -在 Python 示例程序中采用参数绑定的写入方式。(开发中) +在 Python 示例程序中采用多进程的架构。写任务中同样采用拼装 SQL 的方式写入。 +### 主进程 + +
+ +main 函数 + +```python +{{#include docs/examples/python/highvolume_example.py:main}} +``` + +
+ +
+DataBaseMonitor + +```python +{{#include docs/examples/python/highvolume_example.py:DataBaseMonitor}} +``` + +
+ +### 读进程 + +
+ +启动函数 + +```python +{{#include docs/examples/python/highvolume_example.py:read}} +``` + +
+ +
+ +MockDataSource + +```python +{{#include docs/examples/python/highvolume_example.py:MockDataSource}} +``` + +
- + + +
+ +SQLWriter + +```python +{{#include docs/examples/python/highvolume_example.py:SQLWriter}} +``` + +
+ +### 执行示例程序 + +``` +git clone git@github.com:taosdata/TDengine.git +git checkout -t 2.6 +cd docs/examples/python/ +python3 highvolume_example.py +``` \ No newline at end of file