提交 2fc88d32 编写于 作者: D dingbo

docs: test python example

上级 21bcfbce
...@@ -47,16 +47,12 @@ class DataBaseMonitor: ...@@ -47,16 +47,12 @@ class DataBaseMonitor:
return int(r[1]) return int(r[1])
def stat_and_print(self): def stat_and_print(self):
try:
last_count = 0 last_count = 0
while True: while True:
time.sleep(10) time.sleep(10)
count = self.get_count() count = self.get_count()
logging.info(f"count={count} speed={(count - last_count) / 10}") logging.info(f"count={count} speed={(count - last_count) / 10}")
last_count = count last_count = count
except KeyboardInterrupt:
[p.terminate() for p in read_processes]
[p.terminate() for p in write_processes]
# ANCHOR_END: DataBaseMonitor # ANCHOR_END: DataBaseMonitor
...@@ -154,6 +150,7 @@ class SQLWriter: ...@@ -154,6 +150,7 @@ class SQLWriter:
self._buffered_count = 0 self._buffered_count = 0
def execute_sql(self, sql): def execute_sql(self, sql):
self.log.debug(sql)
try: try:
self._conn.execute(sql) self._conn.execute(sql)
except taos.Error as e: except taos.Error as e:
...@@ -258,7 +255,12 @@ def main(): ...@@ -258,7 +255,12 @@ def main():
p.start() p.start()
read_processes.append(p) read_processes.append(p)
try:
database_monitor.stat_and_print() 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 # ANCHOR_END: main
......
...@@ -39,9 +39,13 @@ title: 高效写入 ...@@ -39,9 +39,13 @@ title: 高效写入
3. 模拟生成的总表数。默认为 1000。将会平分给各个读线程。 3. 模拟生成的总表数。默认为 1000。将会平分给各个读线程。
4. 每批最大数据量。默认为 3000。 4. 每批最大数据量。默认为 3000。
```java title="主程序" <details>
<summary>主程序</summary>
```java
{{#include docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java:main}} {{#include docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java:main}}
``` ```
</details>
队列容量(taskQueueCapacity)也是与性能有关的参数,可通过修改程序调节。一般来讲,队列容量越大,入队被阻塞的概率越小,队列的吞吐量越大,但是内存占用也会越大。 队列容量(taskQueueCapacity)也是与性能有关的参数,可通过修改程序调节。一般来讲,队列容量越大,入队被阻塞的概率越小,队列的吞吐量越大,但是内存占用也会越大。
...@@ -163,8 +167,78 @@ TDENGINE_JDBC_URL="jdbc:TAOS://localhost:6030?user=root&password=taosdata" ...@@ -163,8 +167,78 @@ TDENGINE_JDBC_URL="jdbc:TAOS://localhost:6030?user=root&password=taosdata"
## Python 示例程序 ## Python 示例程序
在 Python 示例程序中采用参数绑定的写入方式。(开发中) 在 Python 示例程序中采用多进程的架构。写任务中同样采用拼装 SQL 的方式写入。
### 主进程
<details>
<summary>main 函数</summary>
```python
{{#include docs/examples/python/highvolume_example.py:main}}
```
</details>
<details>
<summary>DataBaseMonitor</summary>
```python
{{#include docs/examples/python/highvolume_example.py:DataBaseMonitor}}
```
</details>
### 读进程
<details>
<!-- ```python title="Python 示例程序" <summary>启动函数</summary>
```python
{{#include docs/examples/python/highvolume_example.py:read}}
```
</details>
<details>
``` --> <summary>MockDataSource</summary>
```python
{{#include docs/examples/python/highvolume_example.py:MockDataSource}}
```
</details>
### 写进程
<details>
<summary>启动函数</summary>
```python
{{#include docs/examples/python/highvolume_example.py:write}}
```
</details>
<details>
<summary>SQLWriter</summary>
```python
{{#include docs/examples/python/highvolume_example.py:SQLWriter}}
```
</details>
### 执行示例程序
```
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册