Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating kafka logger to use the batch processor util #1358

Merged
merged 4 commits into from
Apr 29, 2020

Conversation

sshniro
Copy link
Member

@sshniro sshniro commented Mar 27, 2020

Summary

Updating kafka logger to use the batch processor util.

Depends on #1349

@Akayeshmantha
Copy link
Member

Akayeshmantha commented Mar 29, 2020

Hi @sshniro I think Kafka logger does not needs to use the batch processor since it already has the capability to push to the topic in an asynchronous way. Lua resty Kafka already has the feature already inbuilt I already mentioned that in the documentation file of the logger

The message will write to the buffer first. It will send to the Kafka server when the buffer exceeds the batch_num or every flush_time flush the buffer in Async mode

cc :- @membphis wdyt ?

@membphis
Copy link
Member

@Akayeshmantha I agree with you. The current way is simpler and enough.

@sshniro
Copy link
Member Author

sshniro commented Mar 30, 2020

Closing the PR as agreed to use the builtin buffer of the library.

@sshniro sshniro closed this Mar 30, 2020
@sshniro sshniro reopened this Mar 31, 2020
@sshniro
Copy link
Member Author

sshniro commented Mar 31, 2020

Reopening PR due to the max number of timers which could be executed within a period

@sshniro
Copy link
Member Author

sshniro commented Apr 14, 2020

@membphis the following PR is ready for review.

@sshniro sshniro requested a review from membphis April 14, 2020 06:06
@moonming
Copy link
Member

@membphis please take a look

return
end

buffers[entry.route_id] = log_buffer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one question:

If there are no more new logs to be sent later, how to release the log_buffer object?
If the log_buffer is useless, how to delete it from buffers? If we don't delete it, it will make the buffers bigger.

we need to control the max count number of timer. the default value is 1024 for each worker process.

https://github.com/openresty/lua-nginx-module#lua_max_pending_timers

Copy link
Member Author

@sshniro sshniro Apr 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, @membphis I was also thinking about this problem,
For the memory problem:
we need to write a timer function which executes in all active loggers and finds stale buffer objects and remove the variable. Maybe it can run every 30 mins?

For the timer problem:
The buffer by default has an inactive timeout. If we don't send any logs for 30 seconds, by default it will send the existing logs and will not create any additional timers. Due to this fact, we won't be creating timers for inactive buffers. Only active buffers will have a timer running.

If we agree on the memory optimization technique, then I can send the fix in another PR.

A practical bottleneck is if a user configures like 1024 routes with a logger and actively using all the routes.
But I assume its not a practical scenario. To tackle this scenario we might have to have a global logger instead of a route based logger.

Copy link
Member Author

@sshniro sshniro Apr 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created an issue to remove stale objects from memory:
#1494

The following issue is to create a global logger, to resolve the issue from having more than 1024 loggers running concurrently:
#1492

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@membphis any update on this?

@sshniro
Copy link
Member Author

sshniro commented Apr 28, 2020

A PR has been created to remove stale objects from the buffer table
#1520

@membphis membphis merged commit c6cc2b5 into apache:master Apr 29, 2020
@membphis
Copy link
Member

membphis commented Apr 29, 2020

A PR has been created to remove stale objects from the buffer table
#1520

ok, got you. this PR has been merge first, then we can resolve it in PR #1520 .

I am still thinking about how to solve it in a simple way.

@sshniro
Copy link
Member Author

sshniro commented Apr 29, 2020

We are now creating a batch processor per route id: Just to reduce the number of keys getting created how about we create only one batch processor, if the host port and timeout values are the same? @membphis

Because in reality, people will only have a single external log management platform.

So when a request comes:

local key = con.host .. conf.port .. conf.timeout .. conf.retry
local buffer = buffers[key]

nic-chen pushed a commit to nic-chen/apisix that referenced this pull request Apr 30, 2020
* apisix/master:
  change: limit the maximum length of Lua code to 100. (apache#1525)
  doc: fixed wrong configurations in the logger docs (apache#1530)
  feature: add batch request plugin. (apache#1388)
  plugin(kafka-logger): Updating kafka logger to use the batch processor util (apache#1358)
  test: reindex by tools `reindex`. (apache#1519)
  fix: skip tombstone mark when iterating the global values (apache#1517)
  bugfix: init `clean_handlers` when add new item from etcd. (apache#1412)
  doc: fix the doc style for serverless*.md (apache#1511)
  test: check lua code style in all Lua file under apisix/ (apache#1518)
  feat: support saving k8s deployment info to upstream (apache#1502)
  doc: update steps of build dashboard. (apache#1506)
  rocks: used tag instead of branch. (apache#1503)
  test: fix regex usage in some cases (apache#1504)
  doc: add short introduction about how to change log level (apache#1484)
  bugfix(lrucache): when creating cached objects, use resty-lock to avoid repeated creation. (apache#1486)
  bug: fixed wrong string join in limit-count plugin. (apache#1487)
  doc(readme.md): upload Node.js version for building dashboard. (apache#1485)
  release: released 1.2 version. (apache#1436)

# Conflicts:
#	bin/apisix
#	t/node/upstream.t
SaberMaster pushed a commit to SaberMaster/incubator-apisix that referenced this pull request Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants