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

Implement an EventBus system to publish events and metrics #124

Closed
pulse00 opened this issue Aug 27, 2015 · 5 comments
Closed

Implement an EventBus system to publish events and metrics #124

pulse00 opened this issue Aug 27, 2015 · 5 comments
Assignees
Labels
type: feature A new feature
Milestone

Comments

@pulse00
Copy link

pulse00 commented Aug 27, 2015

I'd like to propose to continue the discussion started here in a separate issue.

Similar to the EventBus mechanism in the couchbase sdk, lettuce could introduce an EventBus emitting RedisEvents:

RedisClient client = new RedisClient("localhost")

client
    .eventBus()
    .get()
    .filter(event -> event.type().equals(EventType.SERVER))
    .subscribe(System.err::println);

This EventBus system could be used both by lettuce and spinach.

My proposal would be to initially create 2 types of events: EventType.SERVER (which would emit any information concerning the redis cluster) and EventType.CLIENT (which would emit any information concerning the client itself).

Questions

  • How should the Observable emit events? Something like:
Schedulers.newThread().createWorker().schedulePeriodically(() -> subject.onNext(redisEvent), 0, 1, TimeUnit.SECONDS);
@mp911de mp911de added the type: feature A new feature label Aug 27, 2015
@mp911de
Copy link
Collaborator

mp911de commented Aug 27, 2015

Thanks, that's an amazing approach to creating more value for the user. I like the cluster events idea very much. The metrics/event bus story tackles a couple aspect:

  • Where to manage/instantiate the event bus: There can be many RedisClient instances, and there are already ClientOptions. It would be great having a way to either distinct/combine/reuse event busses so one can decide where to collect metrics
  • Emission of events and collecting data for the events: On which level aggregate network latencies. I tend to say per connection (IP quadruple) and per command type. That would result in a view that reveals latencies for a particular connection per command type (GET, SET, ...)
  • Emission of events: Should be a configurable period that clears the aggregation values after emitting the events
  • Aggregation: We certainly don't want to emit every command completion as event, rather aggregate a couple of commands until the metrics event is dispatched
  • What means network latency to us? Until the first byte of the command comes back? Until the command is finished? There is a huge difference since a lot of things happen within the JDK until the command is completed. The streaming API, for instance, allows to pass in a callback that is invoked on every data element. One could Thread.sleep(1000) within the callback that causes the time until command completion to explode. The only reasonable solution seems to me to collect both times.
  • Command-Retry also comes into play for the cluster part. A command can be rejected with the MOVED or ASK redirect and then the command is dispatched to the appropriate node

I'm not sure, whether this a 4.x or a 3.x(3.4) topic. Introducing rxjava to 3.4 is not a big deal. The result of the ticket and the metrics/event bus seems really amazing to me and I'm looking forward to get it into lettuce and make it available for clients built on top of lettuce such as spinach.

@mp911de
Copy link
Collaborator

mp911de commented Sep 14, 2015

See also #110. The event bus could be provided by a ClientConfig instead of client options. Client options are somewhat lightweight and can be replaced while using the client. The event bus is more like infrastructure and should not be changed during operations.

@mp911de mp911de added this to the Lettuce 3.4 milestone Sep 22, 2015
@mp911de mp911de changed the title Implement an EventBus system Implement an EventBus system to publish events and metrics Sep 22, 2015
mp911de added a commit that referenced this issue Sep 22, 2015
@mp911de mp911de self-assigned this Sep 22, 2015
@mp911de
Copy link
Collaborator

mp911de commented Sep 22, 2015

Events:

  • Connect/Disconnect
    • Payload: Host-Identifier, Connection?
  • Exception in processing Leave it out for now.
    • Payload: Host-Identifier, Connection?, current active command?
  • Latency Metrics event
    • Payload: Set of metrics, each latency metric has a key of the Host-Identifier and command type and contains the min/max/count and percentiles of the total duration (from writing the command until it is complete)

The event bus deprecates then the existing ConnectionEvents. Hope this makes sense.

@mp911de
Copy link
Collaborator

mp911de commented Sep 23, 2015

Command latency example:

Raw output:

CommandLatencyId [local:any -> localhost/127.0.0.1:6479, commandType=FLUSHDB]=[count=23, timeUnit=MICROSECONDS, 
    firstResponse=[min=166, max=1310, percentiles={50.0=227, 90.0=292, 95.0=395,  99.0=1310, 99.9=1310}], 
    completion=   [min=520, max=1892, percentiles={50.0=733, 90.0=937, 95.0=1187, 99.0=1892, 99.9=1892}]]

JSON:

{
  "[local:any -> localhost/127.0.0.1:6479, commandType=FLUSHALL]": {
    "count": 23,
    "timeUnit": "MICROSECONDS",
    "firstResponse": {
      "min": 151,
      "max": 1474,
      "percentiles": {
        "50.0": 232,
        "90.0": 307,
        "95.0": 323,
        "99.0": 1474,
        "99.9": 1474
      }
    },
    "completion": {
      "min": 548,
      "max": 4718,
      "percentiles": {
        "50.0": 794,
        "90.0": 1036,
        "95.0": 1073,
        "99.0": 4718,
        "99.9": 4718
      }
    }
  }
}

mp911de added a commit that referenced this issue Sep 23, 2015
mp911de added a commit that referenced this issue Sep 30, 2015
Implement an EventBus system to publish events and metrics  #124

- Implement the EventBus infrastructure
- Add rxjava dependency
- Implement Network Latency collection and publishing via the EventBus
- Send client connection events using the EventBus
- Sent cluster topology changed event using the EventBus
@mp911de
Copy link
Collaborator

mp911de commented Sep 30, 2015

Implemented.

@mp911de mp911de closed this as completed Sep 30, 2015
mp911de added a commit that referenced this issue Oct 3, 2015
mp911de added a commit that referenced this issue Oct 3, 2015
mp911de added a commit that referenced this issue Oct 8, 2015
Merge client resources and EventBus from 3.4 branch into the 4.x branch and adopt 4.x changes. Issues from 3.4 #110 #124

This commit aggregates the following topics:
- Publish cluster topology changed event using the EventBus
- Publish connection events using the EventBus
- Collect command latencies and publish metrics over the EventBus
- Implement an EventBus system
- Support reusable ClientResources with CDI and Spring
- Provide a reusable client resources for ThreadPools and other expensive resources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants