Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Fixes #4948 | Lazy event parsing #4986

Merged

Conversation

janisz
Copy link
Contributor

@janisz janisz commented Jan 18, 2017

Change SSE event stream handler to use events that are
lazy parsed to JSON. This will reduce CPU time when most events
are filtered and/or when more then one subscriper is connected.

@mesosphere-ci
Copy link

Can one of the admins verify this patch?

1 similar comment
@mesosphere-ci
Copy link

Can one of the admins verify this patch?

@janisz janisz force-pushed the fixes/#4948/lazy_event_parsing branch 2 times, most recently from 6ae7526 to a568f92 Compare January 18, 2017 22:12
Copy link
Contributor

@jasongilanfarr jasongilanfarr left a comment

Choose a reason for hiding this comment

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

Looks pretty good, I think it could actually be a fair amount simpler

val eventType: String = event.eventType
lazy val message: String = Json.stringify(eventToJson(event))
}

sealed trait MarathonEvent {
val eventType: String
val timestamp: String
Copy link
Contributor

Choose a reason for hiding this comment

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

Could have all of these have lazy val jsonString....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry I don't understand. If you are referring to put lazy val jsonString into MarathonEvent Then we need to ignore this filed during serialization. I created new class to distinct data from their view. We use JSON now but we can use Protobuf or something else in the future. Should I move JSONEvent to SSE Actor?

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for forgetting about this... since we control the serialization/deserialization of these, we could have the jsonString as a member and not serialize the field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -16,7 +17,7 @@ import scala.util.Try
trait HttpEventStreamHandle {
def id: String
def remoteAddress: String
def sendEvent(event: String, message: String): Unit
def sendEvent(event: Event): Unit
Copy link
Contributor

Choose a reason for hiding this comment

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

And then force these to be MarathonEvent

@@ -57,10 +55,10 @@ class HttpEventStreamHandleActor(
private[this] def sendAllMessages(): Unit = {
if (outstanding.nonEmpty) {
val toSend = outstanding.reverse
outstanding = List.empty[MarathonEvent]
outstanding = List.empty[JsonEvent]
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer Seq.empty over List.empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -5,11 +5,9 @@ import java.io.EOFException
import akka.actor.{ Actor, ActorLogging, Status }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change the package into a double declaration?

e.g.

package mesosphere.marathon
package core.event.impl.stream```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1,6 +1,7 @@
package mesosphere.marathon.core.event
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you double package this too?

@jasongilanfarr
Copy link
Contributor

ok to test

@janisz janisz force-pushed the fixes/#4948/lazy_event_parsing branch from 27065b0 to a4cb973 Compare January 23, 2017 12:11
@janisz janisz force-pushed the fixes/#4948/lazy_event_parsing branch from a4cb973 to 33a52c1 Compare January 30, 2017 14:10
@janisz
Copy link
Contributor Author

janisz commented Jan 30, 2017

Rebased

@janisz janisz mentioned this pull request Jan 30, 2017
Change SSE event stream handler to use events that are
lazy parsed to JSON. This will reduce CPU time when most events
are filtered and/or when more then one subscriper is connected.
@janisz janisz force-pushed the fixes/#4948/lazy_event_parsing branch from 33a52c1 to de22344 Compare January 30, 2017 21:48
@unterstein unterstein mentioned this pull request Jan 30, 2017
Copy link
Contributor

@jasongilanfarr jasongilanfarr left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@unterstein unterstein left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks!

Copy link
Contributor

@meichstedt meichstedt left a comment

Choose a reason for hiding this comment

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

Thanks!

@unterstein
Copy link
Contributor

Thanks @janisz !

    .  o ..                  
     o . o o.o                
          ...oo               
            __[]__          Shippin'  
         __|_o_o_o\__         it!
         \""""""""""/         
          \. ..  . /          
     ^^^^^^^^^^^^^^^^^^^^

@unterstein unterstein merged commit cbb1df7 into d2iq-archive:master Feb 6, 2017
@janisz janisz deleted the fixes/#4948/lazy_event_parsing branch February 6, 2017 13:45
unterstein pushed a commit that referenced this pull request Feb 6, 2017
Change SSE event stream handler to use events that are
lazy parsed to JSON. This will reduce CPU time when most events
are filtered and/or when more then one subscriper is connected.
janisz added a commit to janisz/marathon that referenced this pull request Feb 6, 2017
@marcomonaco marcomonaco added the pr label Mar 6, 2017
unterstein pushed a commit that referenced this pull request Mar 9, 2017
Change SSE event stream handler to use events that are
lazy parsed to JSON. This will reduce CPU time when most events
are filtered and/or when more then one subscriper is connected.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants