修正chunk size

This commit is contained in:
Yu Sun
2022-07-10 22:11:08 +08:00
parent 459e6baa33
commit 70d1e43c76
4 changed files with 6 additions and 6 deletions

View File

@@ -6,7 +6,7 @@
- [0. HTTP POST: `set_node_data`](#0-http-post-set_node_data)
- [开发环境](#开发环境)
- [技术细节](#技术细节)
- [0. `EdgeManager\EDataCapture\EDataCapture -> set_data()`为什么是以`6507524`为大小chunked的](#0-edgemanageredatacaptureedatacapture---set_data为什么是以6507524为大小chunked的)
- [0. `EdgeManager\EDataCapture\EDataCapture -> set_data()`为什么是以`6710885`为大小chunked的](#0-edgemanageredatacaptureedatacapture---set_data为什么是以6710885为大小chunked的)
## API
@@ -124,7 +124,7 @@ psql -h localhost -U postgres
## 技术细节
### 0. `EdgeManager\EDataCapture\EDataCapture -> set_data()`为什么是以`6507524`为大小chunked的
### 0. `EdgeManager\EDataCapture\EDataCapture -> set_data()`为什么是以`6710885`为大小chunked的
首先明确一点根据PostgreSQL的技术架构条件允许的情况下**一次性插入多条记录是效率最高的**,比如:
@@ -152,12 +152,12 @@ PostgreSQL的文档里没有提及这个话题因为源码里为SQL语句的
> 安全起见下述计算假定working_subclass等字段的最大长度均为我们以往约定的45 bytes。
而此处我源码中的SQL语句头长度为131 bytes注意末尾空格
而此处我源码中的SQL语句头长度为138 bytes注意末尾空格
![](imgs/sql_head.png)
单个语句体的长度为165 bytes
单个语句体的长度为160 bytes
![](imgs/sql_body.png)
所以其最多可以一次性插入`(1073741823 - 131) / 165`条记录,向下取整后即为`6507524`
所以其最多可以一次性插入`(1073741823 - 138) / 160`条记录,向下取整后即为`6710885`

View File

@@ -11,7 +11,7 @@ class EDataCapture {
) {}
function set_node_data() {
foreach (array_chunk($this -> post -> param -> data, 6507524, true) as $chunk) {
foreach (array_chunk($this -> post -> param -> data, 6710885, true) as $chunk) {
$sql_head = sprintf(
"INSERT INTO hf_mes_scada_data_capture_node_data_%s (code, v_%s, device_code, batch)
VALUES",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 12 KiB