cleaned up the code and removed the latency chart; #1432
Costa Tsaousis (ktsaou) committed
Dec 25, 2016 at 03:12 UTC
e0acd981b994f8eddd1f6260f5596273b5419541
2 files changed
+36
-44
src/backends.c
+35
-43
@@ -265,11 +265,19 @@ void *backends_main(void *ptr) {
265
rrddim_add(chart_ops, "read", NULL, 1, 1, RRDDIM_ABSOLUTE);
266
}
267
268
+ /*
269
+ * this is misleading - we can only measure the time we need to send data
270
+ * this time is not related to the time required for the data to travel to
271
+ * the backend database and the time that server needed to process them
272
+ *
273
+ * issue #1432 and https://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-2.html
274
+ *
275
RRDSET *chart_latency = rrdset_find("netdata.backend_latency");
276
if(!chart_latency) {
277
chart_latency = rrdset_create("netdata", "backend_latency", NULL, "backend", NULL, "Netdata Backend Latency", "ms", 130620, frequency, RRDSET_TYPE_AREA);
278
rrddim_add(chart_latency, "latency", NULL, 1, 1000, RRDDIM_ABSOLUTE);
279
}
280
+ */
281
282
RRDSET *chart_rusage = rrdset_find("netdata.backend_thread_cpu");
283
if(!chart_rusage) {
@@ -356,53 +364,35 @@ void *backends_main(void *ptr) {
364
// if we are connected, receive a response, without blocking
365
366
if(likely(sock != -1)) {
359
- if(likely(fcntl(sock, F_SETFL, O_NONBLOCK) >= 0)) {
360
- errno = 0;
361
-
362
- // loop through to collect all data
363
- while(sock != -1 && errno != EWOULDBLOCK) {
364
- buffer_need_bytes(response, 4096);
365
-
366
- ssize_t r = recv(sock, &response->buffer[response->len], response->size - response->len, O_NONBLOCK);
367
- if(likely(r > 0)) {
368
- // we received some data
369
- response->len += r;
370
- chart_received_bytes += r;
371
- chart_receptions++;
372
- }
373
- else if(r == 0) {
374
- error("Backend '%s' closed the socket", destination);
375
- close(sock);
376
- sock = -1;
377
- }
378
- else {
379
- // failed to receive data
380
- if(errno != EAGAIN && errno != EWOULDBLOCK) {
381
- error("Cannot receive data from backend '%s'.", destination);
382
- }
383
- }
367
+ errno = 0;
368
+
369
+ // loop through to collect all data
370
+ while(sock != -1 && errno != EWOULDBLOCK) {
371
+ buffer_need_bytes(response, 4096);
372
+
373
+ ssize_t r = recv(sock, &response->buffer[response->len], response->size - response->len, MSG_DONTWAIT);
374
+ if(likely(r > 0)) {
375
+ // we received some data
376
+ response->len += r;
377
+ chart_received_bytes += r;
378
+ chart_receptions++;
379
}
385
-
386
- if(sock != -1) {
387
- // unset O_NONBLOCK
388
- int val = fcntl(sock, F_GETFL, 0);
389
- if(likely(val >= 0)) {
390
- int flags = O_NONBLOCK;
391
- val &= ~flags;
392
- if(unlikely(fcntl(sock, F_SETFL, val) < 0))
393
- error("Cannot unset O_NONBLOCK from backend's '%s' socket.", destination);
380
+ else if(r == 0) {
381
+ error("Backend '%s' closed the socket", destination);
382
+ close(sock);
383
+ sock = -1;
384
+ }
385
+ else {
386
+ // failed to receive data
387
+ if(errno != EAGAIN && errno != EWOULDBLOCK) {
388
+ error("Cannot receive data from backend '%s'.", destination);
389
}
395
- else
396
- error("Cannot get active flags from backend's '%s' socket.", destination);
390
}
398
-
399
- // if we received data, process them
400
- if(buffer_strlen(response))
401
- backend_response_checker(response);
402
- }
403
- else {
404
- error("Cannot set O_NONBLOCK from backend's '%s' socket. Receiving data from backend skipped.", destination);
391
}
392
+
393
+ // if we received data, process them
394
+ if(buffer_strlen(response))
395
+ backend_response_checker(response);
396
}
397
398
// ------------------------------------------------------------------------
@@ -526,9 +516,11 @@ void *backends_main(void *ptr) {
516
rrddim_set(chart_bytes, "received", chart_received_bytes);
517
rrdset_done(chart_bytes);
518
519
+ /*
520
if(chart_latency->counter_done) rrdset_next(chart_latency);
521
rrddim_set(chart_latency, "latency", chart_backend_latency);
522
rrdset_done(chart_latency);
523
+ */
524
525
getrusage(RUSAGE_THREAD, &thread);
526
if(chart_rusage->counter_done) rrdset_next(chart_rusage);
src/socket.c
+1
-1
@@ -7,7 +7,7 @@
7
// [PROTOCOL:]IP[%INTERFACE][:PORT]
8
//
9
// PROTOCOL = tcp or udp
10
-// IP = IPv4 or IPv6 IP or hostname, optionaly enclosed in [] (required for IPv6)
10
+// IP = IPv4 or IPv6 IP or hostname, optionally enclosed in [] (required for IPv6)
11
// INTERFACE = for IPv6 only, the network interface to use
12
// PORT = port number or service name
13