You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
if(isset($_POST['testData'])){
$payload=trim($_POST['testData']);
$conf = new RdKafka\Conf();
//$conf->set('bootstrap.servers', 'kafka:9092');
$conf->set('metadata.broker.list', 'kafka:9092');
$conf->set('socket.timeout.ms', 60); // or socket.blocking.max.ms, depending on librdkafka version
$conf->set('request.timeout.ms', 60); // request timeout
if (function_exists('pcntl_sigprocmask')) {
pcntl_sigprocmask(SIG_BLOCK, array(SIGIO));
$conf->set('internal.termination.signal', SIGIO);
} else {
$conf->set('queue.buffering.max.ms', 1);
}
$producer = new RdKafka\Producer($conf);
$topic="testData";
$kafkaTopic = $producer->newTopic($topic);
$kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, $payload);
$producer->poll(0);
for ($flushRetries = 0; $flushRetries < 10; $flushRetries++) {
$result = $producer->flush(10000);
if (RD_KAFKA_RESP_ERR_NO_ERROR === $result) {
echo "Message Published";
break;
}
}
}
K6 test script
import http from 'k6/http';
import { check } from 'k6';
export let options = {
vus: 300, // 300 virtual users
duration: '30s', // Run test for 30 seconds
};
let counter = 0;
export default function () {
// Generate XML data
let testData = generateSensorDataStringForKafka();
// Make a POST request with XML data as payload
let res = http.post('http://localhost/producer.php', `testData=${testData}`, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
console.log(`Response body: ${res.body}`);
}
// Function to generate fake data
function generateSensorDataStringForKafka() {
let xml = '';
xml += 'dS='+(counter+1)+',FreezeCounter=0,alarmStatus=0,';
xml += '\',temperature=';
xml += Math.floor(Math.random() * (80 - 70 + 1)) + 70;
xml += ',humidity='+(Math.floor(Math.random() * (60 - 50 + 1)) + 50);
return xml;
if(counter>10000) counter=0;
}
Resulted in this output:
The test runs fine until the request count reaches little above 28000, and then It gives the following error.
phpApp | %3|1718821570.096|FAIL|rdkafka#producer-2836| [thrd:kafka:9092/bootstrap]: kafka:9092/bootstrap: Failed to connect to broker at kafka-3.7.kafka-producer-k6_default:9092: Cannot assign requested address (after 6ms in state CONNECT)
phpApp | %3|1718821570.096|FAIL|rdkafka#producer-2816| [thrd:kafka:9092/bootstrap]: kafka:9092/bootstrap: Failed to connect to broker at kafka-3.7.kafka-producer-k6_default:9092: Cannot assign requested address (after 6ms in state CONNECT, 1 identical error(s) suppressed)
rdkafka support | enabled
php-rdkafka ersion | 6.0.3
build date | Jun 21 2024 16:21:00
librdkafka version (runtime) | 1.6.0
librdkafka version (build) | 1.6.0.255
If I wait for a minute or so, and run the test again, it goes as normal at around 1300 req/s, until it hits the 28k mark, and stalls again.
Any idea, what is causing this stall? Been pulling hair on this for a while, can't seem to figure out. Much appreciate any assistance.
php-rdkafka Version
6.0.3
librdkafka Version
1.6
PHP Version
PHP 8.2
Operating System
Windows WSL Docker
Kafka Version
bitnami/kafka:3.7.0
The text was updated successfully, but these errors were encountered:
Nginx Unit with php
If I run the same load test to a basic nothing.php that has a single line
echo "Connected, Got Response";
the K6 test for 30 seconds results in ~7k requests per second. So, this does not seem to be the issue. http_reqs......................: 204813 [6821.635938/s]
Bitnami/kafka:3.7.0
I had someone else test this part, he used python (instead of php), and the test completed without any stalls.
This makes me think that something between php/ rdkafka might be turning out the bottleneck. I may be wrong. But been battling this for a while. Hope someone can throw some light on this.
Description
I am using nginx in docker with kafka. I have the following setup.
DockerFile
docker-compose.yml
php producer, basic example from https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka.examples-producer.html
K6 test script
Resulted in this output:
The test runs fine until the request count reaches little above 28000, and then It gives the following error.
If I wait for a minute or so, and run the test again, it goes as normal at around 1300 req/s, until it hits the 28k mark, and stalls again.
Any idea, what is causing this stall? Been pulling hair on this for a while, can't seem to figure out. Much appreciate any assistance.
php-rdkafka Version
6.0.3
librdkafka Version
1.6
PHP Version
PHP 8.2
Operating System
Windows WSL Docker
Kafka Version
bitnami/kafka:3.7.0
The text was updated successfully, but these errors were encountered: