You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/17 07:32:27 UTC

[GitHub] [apisix] moonming commented on a change in pull request #2727: feat: Improve zipkin span reporter performance

moonming commented on a change in pull request #2727:
URL: https://github.com/apache/apisix/pull/2727#discussion_r524934920



##########
File path: apisix/plugins/zipkin/reporter.lua
##########
@@ -105,38 +104,68 @@ function _M.report(self, span)
         annotations = span.logs
     }
 
-    local i = self.pending_spans_n + 1
-    self.pending_spans[i] = zipkin_span
-    self.pending_spans_n = i
-end
-
-function _M.flush(self)
-    if self.pending_spans_n == 0 then
-
-        return true
+    self.pending_spans_n = self.pending_spans_n + 1
+    if self.processor then
+        self.processor:push(zipkin_span)
     end
+end
 
-    local pending_spans = cjson.encode(self.pending_spans)
-    self.pending_spans = {}
-    self.pending_spans_n = 0
-
+local function send_span(pending_spans, report)
     local httpc = resty_http.new()
-    local res, err = httpc:request_uri(self.endpoint, {
+    local res = httpc:request_uri(report.endpoint, {
         method = "POST",
         headers = {
             ["content-type"] = "application/json",
         },
         body = pending_spans,
+        keepalive = 5000,
+        keepalive_pool = 5
     })
 
-    -- TODO: on failure, retry?
     if not res then
-        return nil, "failed to request: " .. err
+        return nil, "failed: " .. report.endpoint
     elseif res.status < 200 or res.status >= 300 then
         return nil, "failed: " .. res.status .. " " .. res.reason
     end
 
-    return true
+   return true
+end
+
+function _M.init_processor(self)
+    local process_conf = {
+        name = "zipkin_report",
+        retry_delay = 1,
+        batch_max_size = 1000,
+        max_retry_count = 0,
+        buffer_duration = 60,
+        inactive_timeout = 5
+    }
+
+    local flush = function (entries, batch_max_size)
+        if not entries then
+            return true
+        end
+
+        local pending_spans, err
+        if batch_max_size == 1 then
+            pending_spans, err = cjson.encode(entries[1])

Review comment:
       agreed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org