From 33af2c9429f4f78b1ceaf17c19015a49c2524266 Mon Sep 17 00:00:00 2001 From: John P Mayer Jr Date: Sun, 6 Mar 2022 22:25:28 -0500 Subject: [PATCH 1/4] Fairly naive update of dependencies. The AsyncRead adapter changes feel simple enough I haven't yet run the benchmark (need to setup the environment) --- Cargo.toml | 20 ++++++++++---------- src/socket.rs | 15 +++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7036a8a..1b56637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-postgres" -version = "0.5.1" +version = "0.7.0" authors = ["Hexilee "] edition = "2018" license = "MIT" @@ -21,18 +21,18 @@ codecov = { repository = "Hexilee/async-postgres" } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +async-std = "1.10" bytes = "0.5" -tokio-postgres = { version = "0.5", default-features = false } -tokio = "0.2" -async-std = "1.6" +tokio = "1" +tokio-postgres = { version = "0.7", default-features = false } futures = { version = "0.3", default-features = false } [dev-dependencies] -async-std = { version = "1.6", features = ["attributes"] } -tokio = { version = "0.2", features = ["full"] } -tokio-postgres = "0.5" -postgres-native-tls = "0.3" +async-std = { version = "1.10", features = ["attributes"] } +tokio = { version = "1", features = ["full"] } +tokio-postgres = "0.7" +postgres-native-tls = "0.5" native-tls = "0.2" [features] @@ -42,7 +42,7 @@ all-types = [ "with-bit-vec-0_6", "with-chrono-0_4", "with-eui48-0_4", - "with-geo-types-0_4", +# "with-geo-types-0_4", "with-serde_json-1", "with-uuid-0_8", "with-time-0_2" @@ -50,7 +50,7 @@ all-types = [ with-bit-vec-0_6 = ["tokio-postgres/with-bit-vec-0_6"] with-chrono-0_4 = ["tokio-postgres/with-chrono-0_4"] with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"] -with-geo-types-0_4 = ["tokio-postgres/with-geo-types-0_4"] +#with-geo-types-0_4 = ["tokio-postgres/with-geo-types-0_4"] with-serde_json-1 = ["tokio-postgres/with-serde_json-1"] with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"] with-time-0_2 = ["tokio-postgres/with-time-0_2"] diff --git a/src/socket.rs b/src/socket.rs index 87466b8..1860a2e 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -1,8 +1,7 @@ use async_std::io::{self, Read, Write}; -use std::mem::MaybeUninit; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio::io::{AsyncRead, AsyncWrite}; +use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; /// A alias for 'static + Unpin + Send + Read + Write pub trait AsyncReadWriter: 'static + Unpin + Send + Read + Write {} @@ -22,18 +21,14 @@ where } impl AsyncRead for Socket { - #[inline] - unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [MaybeUninit]) -> bool { - false - } - #[inline] fn poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - Pin::new(&mut self.0).poll_read(cx, buf) + buf: &mut ReadBuf<'_>, + ) -> Poll> { + let rawBuf = buf.filled_mut(); + Pin::new(&mut self.0).poll_read(cx, rawBuf).map_ok(|_| ()) } } From 655627ef7519ee1dcd3bf870c8a52ab7973ed09d Mon Sep 17 00:00:00 2001 From: John P Mayer Jr Date: Mon, 7 Mar 2022 10:07:47 -0500 Subject: [PATCH 2/4] updated features. cleaned up some warnings --- Cargo.toml | 12 ++++++++---- src/socket.rs | 3 +-- tests/benchmark.rs | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b56637..ab190ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,16 +41,20 @@ full = ["all-types"] all-types = [ "with-bit-vec-0_6", "with-chrono-0_4", - "with-eui48-0_4", -# "with-geo-types-0_4", + "with-eui48-1", + "with-geo-types-0_7", "with-serde_json-1", "with-uuid-0_8", - "with-time-0_2" + "with-time-0_3" ] + with-bit-vec-0_6 = ["tokio-postgres/with-bit-vec-0_6"] with-chrono-0_4 = ["tokio-postgres/with-chrono-0_4"] with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"] -#with-geo-types-0_4 = ["tokio-postgres/with-geo-types-0_4"] +with-eui48-1 = ["tokio-postgres/with-eui48-1"] +with-geo-types-0_6 = ["tokio-postgres/with-geo-types-0_6"] +with-geo-types-0_7 = ["tokio-postgres/with-geo-types-0_7"] with-serde_json-1 = ["tokio-postgres/with-serde_json-1"] with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"] with-time-0_2 = ["tokio-postgres/with-time-0_2"] +with-time-0_3 = ["tokio-postgres/with-time-0_3"] \ No newline at end of file diff --git a/src/socket.rs b/src/socket.rs index 1860a2e..165113c 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -27,8 +27,7 @@ impl AsyncRead for Socket { cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - let rawBuf = buf.filled_mut(); - Pin::new(&mut self.0).poll_read(cx, rawBuf).map_ok(|_| ()) + Pin::new(&mut self.0).poll_read(cx, buf.filled_mut()).map_ok(|_| ()) } } diff --git a/tests/benchmark.rs b/tests/benchmark.rs index 1f54ccf..06f1de4 100644 --- a/tests/benchmark.rs +++ b/tests/benchmark.rs @@ -12,7 +12,7 @@ fn benchmark() -> Result<(), Box> { let queries = TASKS * QUERIES; let tcp_url = var("TCP_URL")?; let uds_url = var("UDS_URL")?; - let mut tokio_rr = tokio::runtime::Runtime::new()?; + let tokio_rr = tokio::runtime::Runtime::new()?; println!("Benchmark concurrency({}), queries({}):", TASKS, queries); println!(" - async-postgres on async-std runtime:"); From 7fa47fdf5a2dcfc5199727fad3c3c38489c2837b Mon Sep 17 00:00:00 2001 From: John P Mayer Jr Date: Mon, 7 Mar 2022 10:12:08 -0500 Subject: [PATCH 3/4] fix AsyncRead adapter --- src/socket.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/socket.rs b/src/socket.rs index 165113c..e485272 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -1,6 +1,7 @@ use async_std::io::{self, Read, Write}; use std::pin::Pin; use std::task::{Context, Poll}; +use futures::ready; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; /// A alias for 'static + Unpin + Send + Read + Write @@ -27,7 +28,9 @@ impl AsyncRead for Socket { cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - Pin::new(&mut self.0).poll_read(cx, buf.filled_mut()).map_ok(|_| ()) + let read_size = ready!(Pin::new(&mut self.0).poll_read(cx, buf.initialize_unfilled()))?; + buf.advance(read_size); + Poll::Ready(Ok(())) } } From a0c36443800f9de79b532e35bd839ec70510f458 Mon Sep 17 00:00:00 2001 From: John P Mayer Jr Date: Mon, 7 Mar 2022 10:31:35 -0500 Subject: [PATCH 4/4] add tokio-postgres runtime feature, so TLS compiles correctly maybe consider exposing this in the features / adding to default? --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ab190ee..65f45dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ codecov = { repository = "Hexilee/async-postgres" } async-std = "1.10" bytes = "0.5" tokio = "1" -tokio-postgres = { version = "0.7", default-features = false } +tokio-postgres = { version = "0.7", default-features = false, features = ["runtime"] } futures = { version = "0.3", default-features = false }