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

Use 'oj' for performance improvement when oj is installed #748

Merged
merged 9 commits into from
Dec 18, 2015

Conversation

repeatedly
Copy link
Member

oj is faster json library and it improves JSONParser performance.
I tested in_tail with following json.

{"_id":"5671172e7ba230441460f011","index":0,"guid":"3d18838a-ae85-4986-83c7-e4a4acdd7f01","isActive":false,"balance":"$3,929.20","picture":"http://placehold.it/32x32","age":40,"eyeColor":"green","company":"MEDMEX","email":"hardin.sargent@medmex.org","phone":"+1 (865) 468-2885","address":"302 Buffalo Avenue, Bend, Louisiana, 635","latitude":"89.385551","longitude":"75.132185","greeting":"Hello, Hardin! You have 5 unread messages.","favoriteFruit":"banana"}

Result is

  • Yajl
2015-12-16 18:23:37 +0900 [info]: following tail of /Users/repeatedly/tmp/fluentd/json.log
2015-12-16 18:23:38 +0900 [info]: plugin:out_flowcounter_simple count:2003      indicator:num   unit:second
2015-12-16 18:23:39 +0900 [info]: plugin:out_flowcounter_simple count:21037     indicator:num   unit:second
2015-12-16 18:23:40 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:41 +0900 [info]: plugin:out_flowcounter_simple count:20034     indicator:num   unit:second
2015-12-16 18:23:42 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:43 +0900 [info]: plugin:out_flowcounter_simple count:21037     indicator:num   unit:second
2015-12-16 18:23:44 +0900 [info]: plugin:out_flowcounter_simple count:18031     indicator:num   unit:second
2015-12-16 18:23:45 +0900 [info]: plugin:out_flowcounter_simple count:20035     indicator:num   unit:second
2015-12-16 18:23:46 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:47 +0900 [info]: plugin:out_flowcounter_simple count:20035     indicator:num   unit:second
2015-12-16 18:23:48 +0900 [info]: plugin:out_flowcounter_simple count:20035     indicator:num   unit:second
2015-12-16 18:23:49 +0900 [info]: plugin:out_flowcounter_simple count:20034     indicator:num   unit:second
2015-12-16 18:23:50 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:51 +0900 [info]: plugin:out_flowcounter_simple count:20035     indicator:num   unit:second
2015-12-16 18:23:52 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:53 +0900 [info]: plugin:out_flowcounter_simple count:20035     indicator:num   unit:second
2015-12-16 18:23:54 +0900 [info]: plugin:out_flowcounter_simple count:21037     indicator:num   unit:second
2015-12-16 18:23:55 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:56 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:23:57 +0900 [info]: plugin:out_flowcounter_simple count:18031     indicator:num   unit:second
2015-12-16 18:23:58 +0900 [info]: plugin:out_flowcounter_simple count:20035     indicator:num   unit:second
2015-12-16 18:23:59 +0900 [info]: plugin:out_flowcounter_simple count:21036     indicator:num   unit:second
2015-12-16 18:24:00 +0900 [info]: plugin:out_flowcounter_simple count:18032     indicator:num   unit:second
2015-12-16 18:24:01 +0900 [info]: plugin:out_flowcounter_simple count:20034     indicator:num   unit:second
2015-12-16 18:24:02 +0900 [info]: plugin:out_flowcounter_simple count:18032     indicator:num   unit:second
  • Oj
2015-12-16 18:25:09 +0900 [info]: following tail of /Users/repeatedly/tmp/fluentd/json.log
2015-12-16 18:25:10 +0900 [info]: plugin:out_flowcounter_simple count:19033     indicator:num   unit:second
2015-12-16 18:25:11 +0900 [info]: plugin:out_flowcounter_simple count:28048     indicator:num   unit:second
2015-12-16 18:25:12 +0900 [info]: plugin:out_flowcounter_simple count:33058     indicator:num   unit:second
2015-12-16 18:25:13 +0900 [info]: plugin:out_flowcounter_simple count:25043     indicator:num   unit:second
2015-12-16 18:25:14 +0900 [info]: plugin:out_flowcounter_simple count:31054     indicator:num   unit:second
2015-12-16 18:25:15 +0900 [info]: plugin:out_flowcounter_simple count:29050     indicator:num   unit:second
2015-12-16 18:25:16 +0900 [info]: plugin:out_flowcounter_simple count:30053     indicator:num   unit:second
2015-12-16 18:25:17 +0900 [info]: plugin:out_flowcounter_simple count:33057     indicator:num   unit:second
2015-12-16 18:25:18 +0900 [info]: plugin:out_flowcounter_simple count:27047     indicator:num   unit:second
2015-12-16 18:25:19 +0900 [info]: plugin:out_flowcounter_simple count:32056     indicator:num   unit:second
2015-12-16 18:25:20 +0900 [info]: plugin:out_flowcounter_simple count:29050     indicator:num   unit:second
2015-12-16 18:25:21 +0900 [info]: plugin:out_flowcounter_simple count:31054     indicator:num   unit:second
2015-12-16 18:25:22 +0900 [info]: plugin:out_flowcounter_simple count:32056     indicator:num   unit:second
2015-12-16 18:25:23 +0900 [info]: plugin:out_flowcounter_simple count:26045     indicator:num   unit:second
2015-12-16 18:25:24 +0900 [info]: plugin:out_flowcounter_simple count:32056     indicator:num   unit:second
2015-12-16 18:25:25 +0900 [info]: plugin:out_flowcounter_simple count:34059     indicator:num   unit:second
2015-12-16 18:25:26 +0900 [info]: plugin:out_flowcounter_simple count:37064     indicator:num   unit:second
2015-12-16 18:25:27 +0900 [info]: plugin:out_flowcounter_simple count:32056     indicator:num   unit:second
2015-12-16 18:25:28 +0900 [info]: plugin:out_flowcounter_simple count:37064     indicator:num   unit:second
2015-12-16 18:25:29 +0900 [info]: plugin:out_flowcounter_simple count:34059     indicator:num   unit:second
2015-12-16 18:25:30 +0900 [info]: plugin:out_flowcounter_simple count:35061     indicator:num   unit:second
2015-12-16 18:25:31 +0900 [info]: plugin:out_flowcounter_simple count:35061     indicator:num   unit:second
2015-12-16 18:25:32 +0900 [info]: plugin:out_flowcounter_simple count:33057     indicator:num   unit:second

Oj result is better than Yajl so using oj is better when oj is installed.

@repeatedly
Copy link
Member Author

@tagomoris @sonots How about this?

@mr-salty
Copy link
Contributor

Should we use multi_json? It does exactly what we're doing here (selects the best available json library).

@repeatedly
Copy link
Member Author

@mr-salty It is one idea. I considered multi_json first but multi_json adds a overhead.
Parser is called frequently in input plugin so I want to reduce such overhead.
This is why I don't use multi_json in this patch.

@repeatedly
Copy link
Member Author

I added oj support in formatter.

In addition, I added disable_oj parameter for existing users.
If hit dump / load errors with oj, user can use this parameter to avoid oj specific error.
If there is no problem, we can remove this parameter in the future.

@sonots
Copy link
Member

sonots commented Dec 16, 2015

Very interesting. Let us go ahead.

@@ -131,8 +131,22 @@ class JSONFormatter < Formatter
include HandleTagAndTimeMixin
include StructuredFormatMixin

config_param :disable_oj, :bool, :default => false
Copy link
Member

Choose a reason for hiding this comment

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

Option like json_parser oj or json_parser yajl looks better because there exists more parsers (cf. https://github.com/intridea/multi_json#supported-json-engines)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to support more parsers and I want to remove this option in the feature.
So I don't want to use more better name because users may misunderstands fluentd will support another parsers.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, please leave the comment in codes.

repeatedly added a commit that referenced this pull request Dec 18, 2015
Use 'oj' for performance improvement when oj is installed
@repeatedly repeatedly merged commit 955f24d into master Dec 18, 2015
@repeatedly repeatedly deleted the support-oj-in-json-parser branch December 18, 2015 11:50
repeatedly added a commit that referenced this pull request Dec 21, 2015
Use 'oj' for performance improvement when oj is installed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants