Adding basic OR-matching for Streams. #1292
Conversation
dennisoelkers
commented
Jul 8, 2015
|
4a99ac1
to
3494e53
- Adds attribute to streams that defines their matching type - Matching type is AND per default if matching type is not specified - Allowing to specify matching type during stream creation via REST api - Adding basic integration tests
Unbreaks creating a stream with an unspecified matching type.
72d3518
to
db76998
@@ -258,8 +260,11 @@ public void increment() { | |||
} | |||
|
|||
public boolean isMatched() { | |||
// If a stream has multiple stream rules, all of the rules have to match. | |||
return ruleCount == matches; | |||
switch (stream.getMatchingType()) { |
bernd
Jul 13, 2015
Member
How about storing the matching type in a field in the constructor? That would avoid calling stream.getMatchingType()
over and over again.
How about storing the matching type in a field in the constructor? That would avoid calling stream.getMatchingType()
over and over again.
dennisoelkers
Jul 13, 2015
Author
Member
It's a simple getter, so it's probably inlined anyway.
It's a simple getter, so it's probably inlined anyway.
bernd
Jul 14, 2015
Member
Ah, okay. The getter does a hash map lookup, does that get inlined as well?
Ah, okay. The getter does a hash map lookup, does that get inlined as well?
bernd
Jul 14, 2015
Member
Looks like it's getting inlined. Sorry for the noise, just want to understand it. 😃
@ 197 org.graylog2.streams.StreamRouterEngine$StreamMatch::isMatched (91 bytes) inline (hot)
@ 7 org.graylog2.streams.StreamImpl::getMatchingType (28 bytes) inline (hot)
\-> TypeProfile (2700/2700 counts) = org/graylog2/streams/StreamImpl
@ 6 java.util.LinkedHashMap::get (25 bytes) inline (hot)
\-> TypeProfile (2609/2609 counts) = java/util/LinkedHashMap
@ 2 java.util.HashMap::getEntry (86 bytes) inline (hot)
@ 19 java.util.HashMap::hash (55 bytes) inline (hot)
@ 27 java.lang.String::hashCode (55 bytes) inline (hot)
@ 33 java.util.HashMap::indexFor (6 bytes) inline (hot)
@ 68 java.lang.String::equals (81 bytes) (intrinsic)
@ 17 java.util.LinkedHashMap$Entry::recordAccess (35 bytes) inline (hot)
@ 6 java.util.LinkedHashMap::access$000 (5 bytes) accessor
@ 23 java.util.LinkedHashMap$Entry::remove (23 bytes) inline (hot)
@ 28 java.util.LinkedHashMap::access$100 (5 bytes) accessor
@ 31 java.util.LinkedHashMap$Entry::addBefore (30 bytes) inline (hot)
@ 24 org.graylog2.plugin.streams.Stream$MatchingType::valueOf (11 bytes) inline (hot)
@ 4 java.lang.Enum::valueOf (73 bytes) inline (hot)
@ 1 java.lang.Class::enumConstantDirectory (114 bytes) too big
@ 12 java.lang.Enum::ordinal (5 bytes) accessor
Looks like it's getting inlined. Sorry for the noise, just want to understand it.
@ 197 org.graylog2.streams.StreamRouterEngine$StreamMatch::isMatched (91 bytes) inline (hot)
@ 7 org.graylog2.streams.StreamImpl::getMatchingType (28 bytes) inline (hot)
\-> TypeProfile (2700/2700 counts) = org/graylog2/streams/StreamImpl
@ 6 java.util.LinkedHashMap::get (25 bytes) inline (hot)
\-> TypeProfile (2609/2609 counts) = java/util/LinkedHashMap
@ 2 java.util.HashMap::getEntry (86 bytes) inline (hot)
@ 19 java.util.HashMap::hash (55 bytes) inline (hot)
@ 27 java.lang.String::hashCode (55 bytes) inline (hot)
@ 33 java.util.HashMap::indexFor (6 bytes) inline (hot)
@ 68 java.lang.String::equals (81 bytes) (intrinsic)
@ 17 java.util.LinkedHashMap$Entry::recordAccess (35 bytes) inline (hot)
@ 6 java.util.LinkedHashMap::access$000 (5 bytes) accessor
@ 23 java.util.LinkedHashMap$Entry::remove (23 bytes) inline (hot)
@ 28 java.util.LinkedHashMap::access$100 (5 bytes) accessor
@ 31 java.util.LinkedHashMap$Entry::addBefore (30 bytes) inline (hot)
@ 24 org.graylog2.plugin.streams.Stream$MatchingType::valueOf (11 bytes) inline (hot)
@ 4 java.lang.Enum::valueOf (73 bytes) inline (hot)
@ 1 java.lang.Class::enumConstantDirectory (114 bytes) too big
@ 12 java.lang.Enum::ordinal (5 bytes) accessor
dennisoelkers
Jul 14, 2015
Author
Member
No worries, many thanks for your thoughtful investigation! 👍
No worries, many thanks for your thoughtful investigation!
joschi
Jul 14, 2015
Contributor
Hm, but inlining the methods of a hash lookup is still slower than a constant/variable lookup. So if the method is called very often (as in: for every incoming message), we could still benefit from saving the matching type into a final variable in the constructor.
Hm, but inlining the methods of a hash lookup is still slower than a constant/variable lookup. So if the method is called very often (as in: for every incoming message), we could still benefit from saving the matching type into a final variable in the constructor.
dennisoelkers
Jul 14, 2015
Author
Member
It will change with the next PR related to the new stream router engine anyway.
It will change with the next PR related to the new stream router engine anyway.
@@ -95,6 +95,7 @@ public Stream create(CreateStreamRequest cr, String userId) { | |||
streamData.put(StreamImpl.FIELD_CREATOR_USER_ID, userId); | |||
streamData.put(StreamImpl.FIELD_CREATED_AT, Tools.iso8601()); | |||
streamData.put(StreamImpl.FIELD_CONTENT_PACK, cr.contentPack()); | |||
streamData.put(StreamImpl.FIELD_MATCHING_TYPE, cr.matchingType().toString()); |
bernd
Jul 13, 2015
Member
matchingType
in CreateStreamRequest
is @Nullable
so this could fail.
matchingType
in CreateStreamRequest
is @Nullable
so this could fail.
bernd
Jul 13, 2015
Member
Aye, missed that.
Aye, missed that.
joschi
Jul 14, 2015
Contributor
In this case the @Nullable
on the getter should be removed as only the method argument in the factory method is nullable but not the actual attribute: https://github.com/Graylog2/graylog2-server/pull/1292/files#diff-1480db0af34470adda8a855ab7063cb5R49
In this case the @Nullable
on the getter should be removed as only the method argument in the factory method is nullable but not the actual attribute: https://github.com/Graylog2/graylog2-server/pull/1292/files#diff-1480db0af34470adda8a855ab7063cb5R49
dennisoelkers
Jul 14, 2015
Author
Member
Totally correct.
Totally correct.
…ator Adding basic OR-matching for Streams.