Skip to content

Commit

Permalink
perf: enable tcpNoDelay by default
Browse files Browse the repository at this point in the history
In [pgjdbc#2341](pgjdbc#2341) the option to
configure tcpNoDelay was added, with a default value of false.

The previous value of this setting was true, as set in
PGStream.changeSocket(Socket) with the following code:
```
    // Submitted by Jason Venner <jason@idiom.com>. Disable Nagle
    // as we are selective about flushing output only when we
    // really need to.
    connection.setTcpNoDelay(true);
```

`changeSocket()` is called from the `PGStream` constructor, which is
called in `ConnectionFactoryImpl`, and then later we overwrite the value
with the one from the properties.

We had a performance issue when upgrading from 42.2.24 to 42.3.3, and we suspected the
issue in 42.3.2 and confirmed that by passing the property `tcpNoDelay=true` to the driver,
the performance issue was fixed.
  • Loading branch information
obourgain committed Apr 20, 2022
1 parent a7e8a32 commit a350382
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/documentation/head/connect.md
Expand Up @@ -340,7 +340,7 @@ Connection conn = DriverManager.getConnection(url);

* **tcpNoDelay** = boolean

Enable or disable TCP nodelay. The default is `false`.
Enable or disable TCP nodelay. The default is `true`.

* **unknownLength** = int

Expand Down
4 changes: 2 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/PGProperty.java
Expand Up @@ -705,8 +705,8 @@ public enum PGProperty {

TCP_NO_DELAY(
"tcpNoDelay",
"false",
"Enable or disable TCP no delay. The default is (@code false}."
"true",
"Enable or disable TCP no delay. The default is (@code true}."
),
/**
* Specifies the length to return for types of unknown length.
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/core/PGStream.java
Expand Up @@ -113,7 +113,7 @@ public PGStream(PGStream pgStream, int timeout ) throws IOException {
int receiveBufferSize = 1024;
int soTimeout = 0;
boolean keepAlive = false;
boolean tcpNoDelay = false;
boolean tcpNoDelay = true;

/*
Get the existing values before closing the stream
Expand Down

0 comments on commit a350382

Please sign in to comment.