Skip to content

Commit 469f140

Browse files
committed
Avoid unnecessarily acquiring when callbacks aren't set
1 parent dd32234 commit 469f140

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

confluent_kafka/src/confluent_kafka.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,13 @@ static void error_cb (rd_kafka_t *rk, int err, const char *reason, void *opaque)
12151215
PyObject *eo, *result;
12161216
CallState *cs;
12171217

1218-
cs = CallState_get(h);
1218+
/* Avoid grabbing the GIL if it's not needed */
1219+
if (!h->error_cb && err != RD_KAFKA_RESP_ERR__FATAL) {
1220+
/* No callback defined */
1221+
return;
1222+
}
1223+
1224+
cs = CallState_get(h);
12191225

12201226
/* If the client raised a fatal error we'll raise an exception
12211227
* rather than calling the error callback. */
@@ -1226,11 +1232,6 @@ static void error_cb (rd_kafka_t *rk, int err, const char *reason, void *opaque)
12261232
goto crash;
12271233
}
12281234

1229-
if (!h->error_cb) {
1230-
/* No callback defined */
1231-
goto done;
1232-
}
1233-
12341235
eo = KafkaError_new0(err, "%s", reason);
12351236
result = PyObject_CallFunctionObjArgs(h->error_cb, eo, NULL);
12361237
Py_DECREF(eo);
@@ -1243,7 +1244,6 @@ static void error_cb (rd_kafka_t *rk, int err, const char *reason, void *opaque)
12431244
rd_kafka_yield(h->rk);
12441245
}
12451246

1246-
done:
12471247
CallState_resume(cs);
12481248
}
12491249

@@ -1258,12 +1258,14 @@ static void throttle_cb (rd_kafka_t *rk, const char *broker_name, int32_t broker
12581258
PyObject *result, *args;
12591259
CallState *cs;
12601260

1261-
cs = CallState_get(h);
1261+
/* Avoid grabbing the GIL if it's not needed */
12621262
if (!h->throttle_cb) {
12631263
/* No callback defined */
1264-
goto done;
1264+
return;
12651265
}
12661266

1267+
cs = CallState_get(h);
1268+
12671269
ThrottleEvent_type = cfl_PyObject_lookup("confluent_kafka",
12681270
"ThrottleEvent");
12691271

@@ -1309,11 +1311,12 @@ static int stats_cb(rd_kafka_t *rk, char *json, size_t json_len, void *opaque) {
13091311
PyObject *eo = NULL, *result = NULL;
13101312
CallState *cs = NULL;
13111313

1314+
/* Avoid calling the GIL if it's not needed */
1315+
if (json_len == 0) {
1316+
/* No data returned*/
1317+
goto done;
1318+
}
13121319
cs = CallState_get(h);
1313-
if (json_len == 0) {
1314-
/* No data returned*/
1315-
goto done;
1316-
}
13171320

13181321
eo = Py_BuildValue("s", json);
13191322
result = PyObject_CallFunctionObjArgs(h->stats_cb, eo, NULL);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy