Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc61e9c3

Browse files
committed
tokio-postgres: buffer sockets to avoid excessive syscalls
The current implementation forwards all read requests to the operatingsystem through the socket causing excessive system calls. The effect ismagnified when the underlying Socket is wrapped around a TLSimplementation.This commit changes the underlying socket to be read-buffered by defaultwith a buffer size of 16K, following the implementation of the officialclient.Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
1 parent52de269 commitc61e9c3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎tokio-postgres/src/socket.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::io;
22
use std::pin::Pin;
33
use std::task::{Context,Poll};
4-
use tokio::io::{AsyncRead,AsyncWrite,ReadBuf};
4+
use tokio::io::{AsyncRead,AsyncWrite,BufReader,ReadBuf};
55
use tokio::net::TcpStream;
66
#[cfg(unix)]
77
use tokio::net::UnixStream;
88

99
#[derive(Debug)]
1010
enumInner{
11-
Tcp(TcpStream),
11+
Tcp(BufReader<TcpStream>),
1212
#[cfg(unix)]
13-
Unix(UnixStream),
13+
Unix(BufReader<UnixStream>),
1414
}
1515

1616
/// The standard stream type used by the crate.
@@ -21,12 +21,12 @@ pub struct Socket(Inner);
2121

2222
implSocket{
2323
pub(crate)fnnew_tcp(stream:TcpStream) ->Socket{
24-
Socket(Inner::Tcp(stream))
24+
Socket(Inner::Tcp(BufReader::with_capacity(16*1024,stream)))
2525
}
2626

2727
#[cfg(unix)]
2828
pub(crate)fnnew_unix(stream:UnixStream) ->Socket{
29-
Socket(Inner::Unix(stream))
29+
Socket(Inner::Unix(BufReader::with_capacity(16*1024,stream)))
3030
}
3131
}
3232

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp