clickhouse-cpp icon indicating copy to clipboard operation
clickhouse-cpp copied to clipboard

Avoid memory copy in ColumnString and Add Reserve function to reduce memory allocation times

Open King-Authur opened this issue 3 years ago • 4 comments

Avoid memory copy in ColumnString and Add Reserve function to reduce memory allocation times.

King-Authur avatar Jul 21 '22 12:07 King-Authur

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 21 '22 12:07 CLAassistant

In the working environment, we encountered the situation that the clickhouse machine hangs up several times. At this time, the server can receive the client's request, but will not respond, which will cause the client to be stuck in the recv() link, which will affect the subsequent data. write. Adding the timeout config and cooperating with the logic of switching the write replica when the write fails can avoid the above problems.

King-Authur avatar Jul 22 '22 03:07 King-Authur

The clickhouse writing service knows the number of rows of data when accumulating data. At this time, we can directly calculate the memory space they need, and allocate them directly through Reserve, which can reduce the number of memory allocations and reduce the time consuming when constructing columns.

King-Authur avatar Jul 22 '22 08:07 King-Authur

Hi! Thank you for your contribution, there are some issues with this PR though.

There are 3 unrelated features, please split it into 3 PRs:

  • socket timeout
  • ColumnString optimizations
  • Reserve

Please add some tests that cover ColumnString and Reserve. Also, maybe consider making Reserve a virtual method of Column and providing reasonable defaults to other columns (Decimal, Enum, Tuple, etc) too.

Enmk avatar Jul 22 '22 20:07 Enmk

Seems to be inactive, closing. Please feel free to re-open, update, and address highlighted issues.

Enmk avatar Sep 12 '22 11:09 Enmk