iceberg-rust icon indicating copy to clipboard operation
iceberg-rust copied to clipboard

Improvement: reuse the tcp connection when plan files

Open chenzl25 opened this issue 1 year ago • 13 comments

Considering I am trying to read an iceberg table from S3. Currently, plan_files() seems unable to reuse the TCP connection for HTTP requests. It will lead to a relatively high latency. I am not sure whether it is a good practice to enable Connection: keep-alive by default, what do you think?

chenzl25 avatar Aug 05 '24 09:08 chenzl25

Considering I am trying to read an iceberg table from S3. Currently, plan_files() seems unable to reuse the TCP connection for HTTP requests. It will lead to a relatively high latency. I am not sure whether it is a good practice to enable Connection: keep-alive by default, what do you think?

I think the buffering is handles by opendal? cc @Xuanwo

liurenjie1024 avatar Aug 05 '24 12:08 liurenjie1024

Hi, OpenDAL handles those connection-related tasks (by reqwest).

Currently, FileIO builds new operators every time:

https://github.com/apache/iceberg-rust/blob/4083f8109b1059c6e3cb7df7ae50a2c8cdc8a613/crates/iceberg/src/io/storage.rs#L104-L119

I think we can improve this by using the same HTTP client instead.

Xuanwo avatar Aug 05 '24 13:08 Xuanwo

Great, Looking forward to it!

chenzl25 avatar Aug 06 '24 03:08 chenzl25

I have tested duckdb and clickhouse to scan an iceberg table in MinIO as well. They can reuse a TCP connection to send HTTP requests. BTW, clickhouse can reuse connections aggressively.

DuckDB: image

Clickhouse: image

chenzl25 avatar Aug 06 '24 04:08 chenzl25

However, risingwave the database use iceberg-rust seems can't reuse any TCP connection. You can see that every HTTP request is in its own TCP connection.

image

chenzl25 avatar Aug 06 '24 04:08 chenzl25

Thanks for the sharing. I believe this can be addressed by reusing the same http client.

Xuanwo avatar Aug 06 '24 05:08 Xuanwo

We will need https://github.com/apache/opendal/issues/4967 for this. I'm working on it now.

Xuanwo avatar Aug 06 '24 07:08 Xuanwo

We will need apache/opendal#4967 for this. I'm working on it now.

Which opendal's version do we need to bump into?

chenzl25 avatar Aug 06 '24 08:08 chenzl25

Which opendal's version do we need to bump into?

I'm guessing it will be included in our next release 0.49.

Xuanwo avatar Aug 06 '24 08:08 Xuanwo

I have already verified that using a global HTTP client works in this issue and the performance improvement is impressive (about 10 times faster: from 1500+ms to 150+ms). https://github.com/risingwavelabs/iceberg-rust/blob/24bd5869f2779a8b9786b5a6e1f9723844f5a82c/crates/iceberg/src/io.rs#L438-L440

chenzl25 avatar Aug 06 '24 08:08 chenzl25

Also, cc @sdd, who is focusing on the iceberg benchmark now.

Xuanwo avatar Aug 06 '24 08:08 Xuanwo

I also have some local code that reuses the same OpenDAL operator rather than creating a new one each time. I'd not submitted it yet as I wasn't sure of the validity of doing that in every possible scenario but it has been working well for me

sdd avatar Aug 06 '24 10:08 sdd

I also have some local code that reuses the same OpenDAL operator rather than creating a new one each time. I'd not submitted it yet as I wasn't sure of the validity of doing that in every possible scenario but it has been working well for me

Great! I will address https://github.com/apache/opendal/issues/4967 first, then consider the best approach for iceberg-rust.

Xuanwo avatar Aug 06 '24 10:08 Xuanwo