summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund2011-04-28 19:22:50 +0000
committerAndres Freund2011-04-28 19:22:50 +0000
commit1b5a9138b48e7edd42db3f659db69de33671a446 (patch)
treebc96ca8fae011e53fb7e50b5186678a5eb39e197
parentc02d5b7c27d740830379244db4b9ef111bbf0fc8 (diff)
Introduce FrontendProtocollIsV3 shorthand for PG_PROTOCOL_MAJOR(FrontendProtocol)speedup/frontend_protocol
Using the long version in postgres.c SocketBackend introduces noticeable pipeline stalls. pgbench -v -h /tmp/ -U andres -T 200 -c3 -j3 -s 30 -S -M prepared pgbench goes from 23221 to 25128
-rw-r--r--src/backend/postmaster/postmaster.c4
-rw-r--r--src/backend/tcop/postgres.c16
-rw-r--r--src/backend/utils/init/globals.c7
-rw-r--r--src/include/libpq/libpq-be.h1
4 files changed, 22 insertions, 6 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index c0cf0336a1..9b97c268e8 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1678,6 +1678,10 @@ retry1:
* we fail during startup.
*/
FrontendProtocol = proto;
+ if(PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
+ FrontendProtocollIsV3 = true;
+ else
+ FrontendProtocollIsV3 = false;
/* Check we can handle the protocol the frontend is using. */
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index a07661f02a..794e44d0f6 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -362,7 +362,7 @@ SocketBackend(StringInfo inBuf)
{
case 'Q': /* simple query */
doing_extended_query_message = false;
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
+ if (!FrontendProtocollIsV3)
{
/* old style without length word; convert */
if (pq_getstring(inBuf))
@@ -393,7 +393,7 @@ SocketBackend(StringInfo inBuf)
case 'P': /* parse */
doing_extended_query_message = true;
/* these are only legal in protocol 3 */
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
+ if (!FrontendProtocollIsV3)
ereport(FATAL,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("invalid frontend message type %d", qtype)));
@@ -405,7 +405,7 @@ SocketBackend(StringInfo inBuf)
/* mark not-extended, so that a new error doesn't begin skip */
doing_extended_query_message = false;
/* only legal in protocol 3 */
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
+ if (!FrontendProtocollIsV3)
ereport(FATAL,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("invalid frontend message type %d", qtype)));
@@ -416,7 +416,7 @@ SocketBackend(StringInfo inBuf)
case 'f': /* copy fail */
doing_extended_query_message = false;
/* these are only legal in protocol 3 */
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
+ if (!FrontendProtocollIsV3)
ereport(FATAL,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("invalid frontend message type %d", qtype)));
@@ -440,7 +440,7 @@ SocketBackend(StringInfo inBuf)
* after the type code; we can read the message contents independently of
* the type.
*/
- if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
+ if (FrontendProtocollIsV3)
{
if (pq_getmessage(inBuf, 0))
return EOF; /* suitable message already logged */
@@ -3365,6 +3365,10 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
*/
if (secure)
FrontendProtocol = (ProtocolVersion) atoi(optarg);
+ if(PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
+ FrontendProtocollIsV3 = true;
+ else
+ FrontendProtocollIsV3 = false;
break;
case 'W':
@@ -3689,7 +3693,7 @@ PostgresMain(int argc, char *argv[], const char *username)
* Send this backend's cancellation info to the frontend.
*/
if (whereToSendOutput == DestRemote &&
- PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
+ FrontendProtocollIsV3)
{
StringInfoData buf;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index c4c41544a2..b1b793e7db 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -25,6 +25,13 @@
ProtocolVersion FrontendProtocol;
+/*
+ * Using PG_PROTOCOL_MAJOR(FrontendProtocol) < 3 all the time in
+ * postgres.c causes a noticeable amount of pipeline stalls. So we
+ * out-of-online that computation.
+ */
+bool FrontendProtocollIsV3;
+
volatile bool InterruptPending = false;
volatile bool QueryCancelPending = false;
diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h
index 77e190fd1a..fd62b5bde0 100644
--- a/src/include/libpq/libpq-be.h
+++ b/src/include/libpq/libpq-be.h
@@ -183,6 +183,7 @@ typedef struct Port
extern ProtocolVersion FrontendProtocol;
+extern bool FrontendProtocollIsV3;
/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */