Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use pyo3-asyncio to get a fresh tokio runtime #1950

Closed

Conversation

PengLiVectra
Copy link

Description

This PR greatly reduces network connections and dns request volume by the delta-rs library when using Python bindings. The approach here is to utilize pyo3-asyncio's tokio-runtime feature as the source of the Runtime. This yields the same runtime across function calls which preserves connections in the connection pool. The previous code created a new runtime per python function call, which established all new socket connections and issued new DNS requests.

Related Issue(s)

Partly #1315

Testing:

Ran a script that called hundreds of delta operations, and watched tcpdump. Only saw one dns request.

@github-actions github-actions bot added the binding/python Issues for the Python package label Dec 6, 2023

Ok(())
}

pub fn get_py_storage_backend(&self) -> PyResult<filesystem::DeltaFileSystemHandler> {
Ok(filesystem::DeltaFileSystemHandler {
inner: self._table.object_store(),
rt: Arc::new(rt()?),
rt: Arc::new(rt_pyo3()?),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeltaFileSystemHandler uses the runtime in utils.rs, which is not pyo3-asyncio. So I keep the original rt but change name to rt_pyo3. Let me know if you have any suggestions.

Comment on lines +56 to +63
fn rt_pyo3() -> PyResult<tokio::runtime::Runtime> {
tokio::runtime::Runtime::new().map_err(|err| PyRuntimeError::new_err(err.to_string()))
}

#[inline]
fn rt() -> &'static tokio::runtime::Runtime {
pyo3_asyncio::tokio::get_runtime()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just create one global one in a lazy static instead? I don't think we need the pyo3-asyncio dependency.

@ion-elgreco
Copy link
Collaborator

@PengLiVectra can you add the requested suggestion from Will?

ion-elgreco added a commit that referenced this pull request Apr 16, 2024
# Description
As suggested by @wjones127 to create a lazy static runtime, supersedes
this PR: #1950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding/python Issues for the Python package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants