Иван Бурмистров "Строго ориентированная...

Post on 06-May-2015

1.036 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Using Cassandra for event logging

Presentation

Using Cassandra for event logging

Ivan BurmistrovSKB Kontur

December 9th, 2013

Using Cassandra for event logging

EDI

We develop EDI (Electronic data interchange) system.

Using Cassandra for event logging

EDI

We develop EDI (Electronic data interchange) system.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

EventLogger

interface IEventLogger{void Write(Event[] events);Event[] Read(Event exclusiveEvent , int count);

}

Availability for Read and Write.Fast Write.Read with minimal time lag.No events in past while we making Read.Same events chronology in any thread.For any thread events orders for write and read are equals.

Using Cassandra for event logging

Obvious solution

Eventstring EventId;long Timestamp;byte[] Content;

Using Cassandra for event logging

Obvious solution

Write(Event[] events)

Write columns for each event e:e.Timestamp = NowTicks;RowKey = e.Timestamp / Partition;ColumnName = e.Timestamp + ":" + e.EventId;ColumnValue = e.Content;

Read(Event exclusiveEvent, int count)

Execute get_slice from exclusive column;Skip events with Timestamp > NowTicks - TimeLag.

Using Cassandra for event logging

Obvious solution

Write(Event[] events)

Write columns for each event e:e.Timestamp = NowTicks;RowKey = e.Timestamp / Partition;ColumnName = e.Timestamp + ":" + e.EventId;ColumnValue = e.Content;

Read(Event exclusiveEvent, int count)

Execute get_slice from exclusive column;Skip events with Timestamp > NowTicks - TimeLag.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesEasy implementation.Write action is very fast.

DisadvantagesTimeLag = ?TimeLag > WriteTimeout + SyncDiff;TimeLag > ReadTimeout + SyncDiff;TimeLag > Cassandra worst write time;We can’t cache events in unstable zone, if we want to readevents from it. I.e. more requests −→ more CPU for cassandra.

Using Cassandra for event logging

Our algorithm

Eventstring EventId;long Timestamp;byte[] Content;State State (Good or Bad);

Using Cassandra for event logging

Our algorithm

Write(Event event)Timestamp = NowTicks, State = Bad, write event.Are there Good events with bigger Timestamp?No? State = Good, rewrite event.Yes? Delete event and try again.

Using Cassandra for event logging

Our algorithm

Write(Event event)Timestamp = NowTicks, State = Bad, write event.Are there Good events with bigger Timestamp?No? State = Good, rewrite event.Yes? Delete event and try again.

Using Cassandra for event logging

Our algorithm

Write(Event event)Timestamp = NowTicks, State = Bad, write event.Are there Good events with bigger Timestamp?No? State = Good, rewrite event.Yes? Delete event and try again.

Using Cassandra for event logging

Our algorithm

Write(Event event)Timestamp = NowTicks, State = Bad, write event.Are there Good events with bigger Timestamp?No? State = Good, rewrite event.Yes? Delete event and try again.

Using Cassandra for event logging

Our algorithm

ReadWe can read events (same as obvious solution) while it’s Good.

Using Cassandra for event logging

Our algorithm

ReadWe can read events (same as obvious solution) while it’s Good.

Using Cassandra for event logging

Our algorithm

TimeLag = ?TimeLag do not depends on timeouts.Less write intensity −→ less TimeLag.Less cassandra write time −→ less TimeLag.

Using Cassandra for event logging

Our algorithm

TimeLag = ?TimeLag do not depends on timeouts.Less write intensity −→ less TimeLag.Less cassandra write time −→ less TimeLag.

Using Cassandra for event logging

Our algorithm

TimeLag = ?TimeLag do not depends on timeouts.Less write intensity −→ less TimeLag.Less cassandra write time −→ less TimeLag.

Using Cassandra for event logging

Improvements

Improvements

"Are there Good events with bigger Timestamp?" for O(1).Queue write requests and process its by batches.We could remove the dependency from time sync, if NowTickswill be monotonous.

Using Cassandra for event logging

Improvements

Improvements

"Are there Good events with bigger Timestamp?" for O(1).Queue write requests and process its by batches.We could remove the dependency from time sync, if NowTickswill be monotonous.

Using Cassandra for event logging

Improvements

Improvements

"Are there Good events with bigger Timestamp?" for O(1).Queue write requests and process its by batches.We could remove the dependency from time sync, if NowTickswill be monotonous.

Using Cassandra for event logging

Sharding

Simple shardingWe can divide all entities by independent parts.For each part we can use separate eventLogger.

Using Cassandra for event logging

Sharding

Simple shardingWe can divide all entities by independent parts.For each part we can use separate eventLogger.

Using Cassandra for event logging

Sharding

Sharding for readingTimestamp = NowTicks, State = Bad, write events indifferent rows.Are there Good events with bigger Timestamp in any row?No? State = Good, rewrite events.Yes? Delete event and try again.

Using Cassandra for event logging

Sharding

Sharding for readingTimestamp = NowTicks, State = Bad, write events indifferent rows.Are there Good events with bigger Timestamp in any row?No? State = Good, rewrite events.Yes? Delete event and try again.

Using Cassandra for event logging

Sharding

Sharding for readingTimestamp = NowTicks, State = Bad, write events indifferent rows.Are there Good events with bigger Timestamp in any row?No? State = Good, rewrite events.Yes? Delete event and try again.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesSmall size of time lag. For 3500 writes per sec worst time lagis 50ms and 10 events.More cacheable.Easy sharding.Can be independed from time sync.

DisadvantagesMore slow writes. But still enough fast.Limit for writing threads.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesSmall size of time lag. For 3500 writes per sec worst time lagis 50ms and 10 events.More cacheable.Easy sharding.Can be independed from time sync.

DisadvantagesMore slow writes. But still enough fast.Limit for writing threads.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesSmall size of time lag. For 3500 writes per sec worst time lagis 50ms and 10 events.More cacheable.Easy sharding.Can be independed from time sync.

DisadvantagesMore slow writes. But still enough fast.Limit for writing threads.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesSmall size of time lag. For 3500 writes per sec worst time lagis 50ms and 10 events.More cacheable.Easy sharding.Can be independed from time sync.

DisadvantagesMore slow writes. But still enough fast.Limit for writing threads.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesSmall size of time lag. For 3500 writes per sec worst time lagis 50ms and 10 events.More cacheable.Easy sharding.Can be independed from time sync.

DisadvantagesMore slow writes. But still enough fast.Limit for writing threads.

Using Cassandra for event logging

Advantages and disadvantages

AdvantagesSmall size of time lag. For 3500 writes per sec worst time lagis 50ms and 10 events.More cacheable.Easy sharding.Can be independed from time sync.

DisadvantagesMore slow writes. But still enough fast.Limit for writing threads.

Using Cassandra for event logging

Another applications

Another applicationsIndexing. We can use event log as notification about changestate of some objects −→ indexing. Cacheable is very usefulhere!Message queues.

Using Cassandra for event logging

Another applications

Another applicationsIndexing. We can use event log as notification about changestate of some objects −→ indexing. Cacheable is very usefulhere!Message queues.

top related