SlideShare a Scribd company logo
© 2014 Aerospike. All rights reserved.
Concurrent, High-Performance
Data-Access With Go
Khosrow Afroozeh

Engineer

Aerospike
Sunil Sayyaparaju

Engineer

Aerospike
What does High Performance mean?
© 2014 Aerospike. All rights reserved.
North American RTB speeds & feeds
■ 100 millisecond or 150 millisecond ad delivery
■ De-facto standard set in 2004 by Washington Post and others
■ North America is 70 to 90 milliseconds wide
■ Two or three data centers
■ Newyork-Amsterdam is 150 milliseconds
■ Auction is limited to 30 milliseconds
■ Typically closes in 5 milliseconds
■ Winners have more data, better models – in 5
milliseconds
© 2014 Aerospike. All rights reserved.
North American RTB speeds & feeds
■ 1 to 6 billion cookies tracked
■ Some companies track 200M, some track 20B
■ Each bidder has their own data pool
■ Data is your weapon
■ Recent searches, behavior, IP addresses
■ Audience clusters (K-cluster, K-means) from offline Batch Processing
■ “Remnant” from Google, Yahoo is about 0.6 million / sec
■ Facebook exchange: about 0.6 million / sec
■ “others” are 0.5 million / sec
Currently around 2.0M / sec in North America
Layer-Driven Architecture
Request routing and sharding
APP SERVERS
CACHE
DATABASE
STORAGE
CONTENT
DELIVERY NETWORK
LOAD BALANCER
Yet another CACHE
Minimalism Makes a Comeback
APP SERVERS
CACHE
DATABASE
STORAGE
Realtime Wannabe
LOAD BALANCER
Minimalism Makes a Comeback
APP SERVERS
Hybrid NoSQL
Realtime Wannabe Realtime
APP SERVERS
CACHE
DATABASE
STORAGE
LOAD BALANCER
Aerospike is a distributed database
Hint: It is NOT like this!
Replicaset 1 Replicaset 2 Replicaset 3
Application
Coordinators
Hint: It is NOT like this!
Replicaset 1 Replicaset 2 Replicaset 3
Application
Coordinators
Aerospike
Database Nodes
Application
Aerospike
Database Nodes
Application
1) No Hotspots 

– DHT simplifies data
partitioning
2) Smart Client – 1 hop to data,
no load balancers needed
3) Shared Nothing Architecture, 

every node identical - no
coordinators needed
7) XDR – sync’d replication across
data centers ensures Zero Downtime
8) Scale linearly as data-sizes and
workloads increase
9) Add capacity with no service
interruption
4) Single row ACID 

– sync’d replication in cluster
5) Smart Cluster, Zero Touch 

– auto-failover, rebalancing,
rack aware, rolling upgrades...
6) Transactions and long running
tasks prioritized real-time
Benefits of Design:
Client Libraries Need To Do More - TRANSPARENTLY
■ Implements Aerospike API
■ Optimistic row locking
■ Optimized binary protocol
■ Cluster Tracking
■ Learns about cluster changes,
Partition Map
■ Transaction Semantics
■ Global Transaction ID
■ Retransmit and timeout
■ Linearly Scales
■ No extra hop to data
■ No load balancers in the way
Tracking Cluster Changes
Database Nodes
Application
Cluster Tracking
Data is distributed evenly across nodes in a
cluster using the Aerospike Smart Partitions™
algorithm.
■ Even distribution of
■Partitions across nodes
■Records across Partitions
■Data across Flash device
? Need to know Where each key is!
func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
newCluster := &Cluster{...}
// start up cluster maintenance go routine
newCluster.wgTend.Add(1)
go newCluster.clusterBoss(policy)
return newCluster, nil
}
func (clstr *Cluster) clusterBoss(policy *ClientPolicy) {
defer clstr.wgTend.Done()
Loop:
for {
select {
case <-clstr.tendChannel:
// tend channel closed
break Loop
case <-time.After(tendInterval):
if err := clstr.tend(); err != nil {
Logger.Warn(err.Error())
}
}
}
// cleanup code goes here
// close the nodes, ...
}
func (clstr *Cluster) Close() {
if !clstr.closed.Get() {
// send close signal to maintenance channel
close(clstr.tendChannel)
// wait until tend is over
clstr.wgTend.Wait()
}
}
Cluster Tracking
Spawn Goroutine To
Track Cluster Changes
{
func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
newCluster := &Cluster{...}
// start up cluster maintenance go routine
newCluster.wgTend.Add(1)
go newCluster.clusterBoss(policy)
return newCluster, nil
}
func (clstr *Cluster) clusterBoss(policy *ClientPolicy) {
defer clstr.wgTend.Done()
Loop:
for {
select {
case <-clstr.tendChannel:
// tend channel closed
break Loop
case <-time.After(tendInterval):
if err := clstr.tend(); err != nil {
Logger.Warn(err.Error())
}
}
}
// cleanup code goes here
// close the nodes, ...
}
func (clstr *Cluster) Close() {
if !clstr.closed.Get() {
// send close signal to maintenance channel
close(clstr.tendChannel)
// wait until tend is over
clstr.wgTend.Wait()
}
}
Cluster Tracking
On Intervals, Update
Cluster Status
{
func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
newCluster := &Cluster{...}
// start up cluster maintenance go routine
newCluster.wgTend.Add(1)
go newCluster.clusterBoss(policy)
return newCluster, nil
}
func (clstr *Cluster) clusterBoss(policy *ClientPolicy) {
defer clstr.wgTend.Done()
Loop:
for {
select {
case <-clstr.tendChannel:
// tend channel closed
break Loop
case <-time.After(tendInterval):
if err := clstr.tend(); err != nil {
Logger.Warn(err.Error())
}
}
}
// cleanup code goes here
// close the nodes, ...
}
func (clstr *Cluster) Close() {
if !clstr.closed.Get() {
// send close signal to maintenance channel
close(clstr.tendChannel)
// wait until tend is over
clstr.wgTend.Wait()
}
}
Cluster Tracking
Broadcast Closing Of
Cluster
{
func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
newCluster := &Cluster{...}
// start up cluster maintenance go routine
newCluster.wgTend.Add(1)
go newCluster.clusterBoss(policy)
return newCluster, nil
}
func (clstr *Cluster) clusterBoss(policy *ClientPolicy) {
defer clstr.wgTend.Done()
Loop:
for {
select {
case <-clstr.tendChannel:
// tend channel closed
break Loop
case <-time.After(tendInterval):
if err := clstr.tend(); err != nil {
Logger.Warn(err.Error())
}
}
}
// cleanup code goes here
// close the nodes, ...
}
func (clstr *Cluster) Close() {
if !clstr.closed.Get() {
// send close signal to maintenance channel
close(clstr.tendChannel)
// wait until tend is over
clstr.wgTend.Wait()
}
}
Cluster Tracking
Break the loop to clean up
{
How To Stream Back Data From Multiple Nodes
Database Nodes
Application
Queries
1 Goroutine Per Node
Queries are Scatter
And Gather
No Cursors
Data Is Streamed
Back
Might Want To
Continue With Other
Nodes
Errors Are Per Node
Database Nodes
Application
Queries
Goroutine
#1
Goroutine
#2
Goroutine
#3
Errors
Records
Queries
{
Same buffered channel is used for all goroutines
Queries
{
Errors are sent back on a separate channel
7
{
Defer on all producers will ensure Close() is called at least once
Queries
Consumer
Producer #N
{Will not deadlock, all
producers will return
{
The Above code will never panic, or block indefinitely:
• defer on Execute() will ensure Close() is called at least once
• When cancelled channel is closed, even if the Records channel is
full and blocked, select will go through and return from goroutine
Queries
The Above code will never panic, or block indefinitely:
• defer on Execute() will ensure Close() is called at least once
• When cancelled channel is closed, even if the Records channel is
full and blocked, select will go through and return from goroutine
Consumer
Producer #N
{Will not panic, all
producers have already
stopped
Consumption Pattern
Consumer
Fork #N
{Supports
numerous
consumers
Range on
Channel, get
either a Record
or error
Errors do not mean the stream has ended. They carry information about what went wrong, and where
Take away
• Channels are a good abstraction for data streaming
• Easier to avoid deadlocks
• Use the least number of channels and goroutines
• Multiplex on demand
• Goroutines are cheap, but not free
• Pass channels throughout API, don’t ask for new ones
How To Win Against The Garbage Collector
Don’t Create Garbage
• Avoid Memory Allocations
• Might be trickier than you think!
• Pool All Objects
• Buffers
• Hash Objects
• Network Connections
• Reusable Intermediate / Temporary Objects
• Random Number Generators
• sync.Pool is not ideal to pool long living objects
• Integrated into GC, sweeps and deallocates objects too often
• LIFO pools tend to do better regarding CPU cache
• Channels for pool implementation still perform well though
Don’t Reallocate Memory
• Avoid Memory Allocations
• Might be trickier than you think!
• All following code snippets allocate memory:
b := new(bytes.Buffer)
longBuf := bytes.Repeat([]byte{32}, 100)
// Allocation happens in Write to Grow the buffer
b.Write([]byte{32})
// Re-allocation happens in Write to Grow the buffer
b.Write(longBuf)
// allocation happens inside Trim
strings.Trim(" Trim this string ", " ")
h := ripemd160.New()
h.Write(data)
// allocation happens inside Sum()
h.Sum(nil)
// Why? To support the general case
func (d *digest) Sum(in []byte) []byte {
// Make a copy of d0 so that caller can keep writing and summing.
d := *d0
Don’t Reallocate Memory
Pools
Indeterministic Pools are Resource Leaks You Haven’t Found Yet!
* Please apply wisdom to the quip above
*
Pools
• Make Pools Deterministic
• Let User Decide About Parameters Per Use-Case
• Document The Above!
type BufferPool struct {
pool [][]byte
poolSize int
pos int64
maxBufSize int
initBufSize int
mutex sync.Mutex
}
func (bp *BufferPool) Put(buf []byte) {
if len(buf) <= bp.maxBufSize {
...
}
// buffer too big to go back into the pool
}
// a custom buffer pool with fine grained control over its contents
// maxSize: 128KiB
// initial bufferSize: 16 KiB
// maximum buffer size to keep in the pool: 128K
var bufPool = NewBufferPool(512, 16*1024, 128*1024)
// SetCommandBufferPool can be used to customize the command Buffer Pool parameters to calib
// the pool for different workloads
func SetCommandBufferPool(poolSize, initBufSize, maxBufferSize int) {
bufPool = NewBufferPool(poolSize, initBufSize, maxBufferSize)
}
Set & Enforce Limits for
Pooled Buffers
{
{
Set Sensible Defaults
Let Users Tweak Per
Use-Case
type AtomicQueue struct {
items chan interface{}
}
func NewAtomicQueue(size int) *AtomicQueue {
return &AtomicQueue{
items: make(chan interface{}, size),
}
}
func (aq *AtomicQueue) Offer(item interface{}) bool {
// non-blocking send pattern
select {
case aq.items <- item:
return true
default:
}
return false
}
func (aq *AtomicQueue) Poll() interface{} {
// non-blocking read pattern
select {
case item := <-aq.items:
return item
default:
}
return nil
}
Non-Blocking Sync’d Queues Using Channels
Non-blocking Channel Read / Write Is Possible
Non-Blocking
{
{
Generic Pool Using Sync’d Queue
How Does It Perform?
Comparison vs C and Java
100% WRITE 100% READ
50% READ
50% WRITE
C 261K 308K 273K
JAVA 180K 280K 220K
GO 306K 238K 276K
Data Type: String of size 2000
Fastest Slowest
Transactions Per Second
Comparison vs C and Java
100% WRITE 100% READ
50% READ
50% WRITE
C 299K 334K 307K
JAVA 308K 339K 325K
GO 338K 328K 330K
Data Type: Integer (8 Bytes)
Fastest Slowest
Transactions Per Second
Thank you
@parshua
khosrow@aerospike.com
@sunilvirus
sunil@aerospike.com

More Related Content

What's hot

MySQL Head-to-Head
MySQL Head-to-HeadMySQL Head-to-Head
MySQL Head-to-Head
Patrick McGarry
 
Linux Block Cache Practice on Ceph BlueStore - Junxin Zhang
Linux Block Cache Practice on Ceph BlueStore - Junxin ZhangLinux Block Cache Practice on Ceph BlueStore - Junxin Zhang
Linux Block Cache Practice on Ceph BlueStore - Junxin Zhang
Ceph Community
 
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph EnterpriseRed Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
Red_Hat_Storage
 
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
DataStax
 
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
DataStax
 
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environmentHBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon
 
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John HaanBasic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
Ceph Community
 
Solr on Docker - the Good, the Bad and the Ugly
Solr on Docker - the Good, the Bad and the UglySolr on Docker - the Good, the Bad and the Ugly
Solr on Docker - the Good, the Bad and the Ugly
Sematext Group, Inc.
 
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
DataStax
 
Your 1st Ceph cluster
Your 1st Ceph clusterYour 1st Ceph cluster
Your 1st Ceph cluster
Mirantis
 
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Altinity Ltd
 
Update on OpenTSDB and AsyncHBase
Update on OpenTSDB and AsyncHBase Update on OpenTSDB and AsyncHBase
Update on OpenTSDB and AsyncHBase
HBaseCon
 
SignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series DatabaseSignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series Database
DataStax Academy
 
ELK: Moose-ively scaling your log system
ELK: Moose-ively scaling your log systemELK: Moose-ively scaling your log system
ELK: Moose-ively scaling your log system
Avleen Vig
 
(CMP402) Amazon EC2 Instances Deep Dive
(CMP402) Amazon EC2 Instances Deep Dive(CMP402) Amazon EC2 Instances Deep Dive
(CMP402) Amazon EC2 Instances Deep Dive
Amazon Web Services
 
Ceph Object Storage at Spreadshirt
Ceph Object Storage at SpreadshirtCeph Object Storage at Spreadshirt
Ceph Object Storage at Spreadshirt
Jens Hadlich
 
Seastar @ NYCC++UG
Seastar @ NYCC++UGSeastar @ NYCC++UG
Seastar @ NYCC++UG
Avi Kivity
 
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on CephBuild an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
Rongze Zhu
 
Ceph Performance and Sizing Guide
Ceph Performance and Sizing GuideCeph Performance and Sizing Guide
Ceph Performance and Sizing Guide
Jose De La Rosa
 
Ceph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance Barriers
Ceph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance BarriersCeph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance Barriers
Ceph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance Barriers
Ceph Community
 

What's hot (20)

MySQL Head-to-Head
MySQL Head-to-HeadMySQL Head-to-Head
MySQL Head-to-Head
 
Linux Block Cache Practice on Ceph BlueStore - Junxin Zhang
Linux Block Cache Practice on Ceph BlueStore - Junxin ZhangLinux Block Cache Practice on Ceph BlueStore - Junxin Zhang
Linux Block Cache Practice on Ceph BlueStore - Junxin Zhang
 
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph EnterpriseRed Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
 
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
 
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
Storing Cassandra Metrics (Chris Lohfink, DataStax) | C* Summit 2016
 
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environmentHBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environment
 
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John HaanBasic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
 
Solr on Docker - the Good, the Bad and the Ugly
Solr on Docker - the Good, the Bad and the UglySolr on Docker - the Good, the Bad and the Ugly
Solr on Docker - the Good, the Bad and the Ugly
 
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
Terror & Hysteria: Cost Effective Scaling of Time Series Data with Cassandra ...
 
Your 1st Ceph cluster
Your 1st Ceph clusterYour 1st Ceph cluster
Your 1st Ceph cluster
 
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
 
Update on OpenTSDB and AsyncHBase
Update on OpenTSDB and AsyncHBase Update on OpenTSDB and AsyncHBase
Update on OpenTSDB and AsyncHBase
 
SignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series DatabaseSignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series Database
 
ELK: Moose-ively scaling your log system
ELK: Moose-ively scaling your log systemELK: Moose-ively scaling your log system
ELK: Moose-ively scaling your log system
 
(CMP402) Amazon EC2 Instances Deep Dive
(CMP402) Amazon EC2 Instances Deep Dive(CMP402) Amazon EC2 Instances Deep Dive
(CMP402) Amazon EC2 Instances Deep Dive
 
Ceph Object Storage at Spreadshirt
Ceph Object Storage at SpreadshirtCeph Object Storage at Spreadshirt
Ceph Object Storage at Spreadshirt
 
Seastar @ NYCC++UG
Seastar @ NYCC++UGSeastar @ NYCC++UG
Seastar @ NYCC++UG
 
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on CephBuild an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
 
Ceph Performance and Sizing Guide
Ceph Performance and Sizing GuideCeph Performance and Sizing Guide
Ceph Performance and Sizing Guide
 
Ceph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance Barriers
Ceph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance BarriersCeph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance Barriers
Ceph Day Melbourne - Ceph on All-Flash Storage - Breaking Performance Barriers
 

Similar to Aerospike Go Language Client

Three Perspectives on Measuring Latency
Three Perspectives on Measuring LatencyThree Perspectives on Measuring Latency
Three Perspectives on Measuring Latency
ScyllaDB
 
Cassandra and drivers
Cassandra and driversCassandra and drivers
Cassandra and drivers
Ben Bromhead
 
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
Lucidworks
 
Monomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMonomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted Data
Mostafa Arjmand
 
Ceph QoS: How to support QoS in distributed storage system - Taewoong Kim
Ceph QoS: How to support QoS in distributed storage system - Taewoong KimCeph QoS: How to support QoS in distributed storage system - Taewoong Kim
Ceph QoS: How to support QoS in distributed storage system - Taewoong Kim
Ceph Community
 
Much Faster Networking
Much Faster NetworkingMuch Faster Networking
Much Faster Networking
C4Media
 
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
confluent
 
SDAccel Design Contest: Vivado HLS
SDAccel Design Contest: Vivado HLSSDAccel Design Contest: Vivado HLS
SDAccel Design Contest: Vivado HLS
NECST Lab @ Politecnico di Milano
 
Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...
Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...
Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...
Compuware
 
XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @Cloudflare
C4Media
 
Chronix Poster for the Poster Session FAST 2017
Chronix Poster for the Poster Session FAST 2017Chronix Poster for the Poster Session FAST 2017
Chronix Poster for the Poster Session FAST 2017
Florian Lautenschlager
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Anne Nicolas
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
Alexandre Moneger
 
«Scrapy internals» Александр Сибиряков, Scrapinghub
«Scrapy internals» Александр Сибиряков, Scrapinghub«Scrapy internals» Александр Сибиряков, Scrapinghub
«Scrapy internals» Александр Сибиряков, Scrapinghub
it-people
 
Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005dflexer
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...
SignalFx
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scale
thelabdude
 
InfluxEnterprise Architecture Patterns by Tim Hall & Sam Dillard
InfluxEnterprise Architecture Patterns by Tim Hall & Sam DillardInfluxEnterprise Architecture Patterns by Tim Hall & Sam Dillard
InfluxEnterprise Architecture Patterns by Tim Hall & Sam Dillard
InfluxData
 

Similar to Aerospike Go Language Client (20)

Three Perspectives on Measuring Latency
Three Perspectives on Measuring LatencyThree Perspectives on Measuring Latency
Three Perspectives on Measuring Latency
 
Cassandra and drivers
Cassandra and driversCassandra and drivers
Cassandra and drivers
 
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Monomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMonomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted Data
 
Ceph QoS: How to support QoS in distributed storage system - Taewoong Kim
Ceph QoS: How to support QoS in distributed storage system - Taewoong KimCeph QoS: How to support QoS in distributed storage system - Taewoong Kim
Ceph QoS: How to support QoS in distributed storage system - Taewoong Kim
 
Much Faster Networking
Much Faster NetworkingMuch Faster Networking
Much Faster Networking
 
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
 
SDAccel Design Contest: Vivado HLS
SDAccel Design Contest: Vivado HLSSDAccel Design Contest: Vivado HLS
SDAccel Design Contest: Vivado HLS
 
Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...
Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...
Using Compuware Strobe to Save CPU: 4 Real-life Cases from the Files of CPT G...
 
XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @Cloudflare
 
Chronix Poster for the Poster Session FAST 2017
Chronix Poster for the Poster Session FAST 2017Chronix Poster for the Poster Session FAST 2017
Chronix Poster for the Poster Session FAST 2017
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
«Scrapy internals» Александр Сибиряков, Scrapinghub
«Scrapy internals» Александр Сибиряков, Scrapinghub«Scrapy internals» Александр Сибиряков, Scrapinghub
«Scrapy internals» Александр Сибиряков, Scrapinghub
 
Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005
 
ThesisPresentation_Upd
ThesisPresentation_UpdThesisPresentation_Upd
ThesisPresentation_Upd
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scale
 
InfluxEnterprise Architecture Patterns by Tim Hall & Sam Dillard
InfluxEnterprise Architecture Patterns by Tim Hall & Sam DillardInfluxEnterprise Architecture Patterns by Tim Hall & Sam Dillard
InfluxEnterprise Architecture Patterns by Tim Hall & Sam Dillard
 

Recently uploaded

RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

Aerospike Go Language Client

  • 1. © 2014 Aerospike. All rights reserved. Concurrent, High-Performance Data-Access With Go Khosrow Afroozeh Engineer Aerospike Sunil Sayyaparaju Engineer Aerospike
  • 2. What does High Performance mean?
  • 3. © 2014 Aerospike. All rights reserved. North American RTB speeds & feeds ■ 100 millisecond or 150 millisecond ad delivery ■ De-facto standard set in 2004 by Washington Post and others ■ North America is 70 to 90 milliseconds wide ■ Two or three data centers ■ Newyork-Amsterdam is 150 milliseconds ■ Auction is limited to 30 milliseconds ■ Typically closes in 5 milliseconds ■ Winners have more data, better models – in 5 milliseconds
  • 4. © 2014 Aerospike. All rights reserved. North American RTB speeds & feeds ■ 1 to 6 billion cookies tracked ■ Some companies track 200M, some track 20B ■ Each bidder has their own data pool ■ Data is your weapon ■ Recent searches, behavior, IP addresses ■ Audience clusters (K-cluster, K-means) from offline Batch Processing ■ “Remnant” from Google, Yahoo is about 0.6 million / sec ■ Facebook exchange: about 0.6 million / sec ■ “others” are 0.5 million / sec Currently around 2.0M / sec in North America
  • 5. Layer-Driven Architecture Request routing and sharding APP SERVERS CACHE DATABASE STORAGE CONTENT DELIVERY NETWORK LOAD BALANCER Yet another CACHE
  • 6. Minimalism Makes a Comeback APP SERVERS CACHE DATABASE STORAGE Realtime Wannabe LOAD BALANCER
  • 7. Minimalism Makes a Comeback APP SERVERS Hybrid NoSQL Realtime Wannabe Realtime APP SERVERS CACHE DATABASE STORAGE LOAD BALANCER
  • 8. Aerospike is a distributed database
  • 9. Hint: It is NOT like this! Replicaset 1 Replicaset 2 Replicaset 3 Application Coordinators
  • 10. Hint: It is NOT like this! Replicaset 1 Replicaset 2 Replicaset 3 Application Coordinators
  • 12. Aerospike Database Nodes Application 1) No Hotspots 
 – DHT simplifies data partitioning 2) Smart Client – 1 hop to data, no load balancers needed 3) Shared Nothing Architecture, 
 every node identical - no coordinators needed 7) XDR – sync’d replication across data centers ensures Zero Downtime 8) Scale linearly as data-sizes and workloads increase 9) Add capacity with no service interruption 4) Single row ACID 
 – sync’d replication in cluster 5) Smart Cluster, Zero Touch 
 – auto-failover, rebalancing, rack aware, rolling upgrades... 6) Transactions and long running tasks prioritized real-time Benefits of Design:
  • 13. Client Libraries Need To Do More - TRANSPARENTLY ■ Implements Aerospike API ■ Optimistic row locking ■ Optimized binary protocol ■ Cluster Tracking ■ Learns about cluster changes, Partition Map ■ Transaction Semantics ■ Global Transaction ID ■ Retransmit and timeout ■ Linearly Scales ■ No extra hop to data ■ No load balancers in the way
  • 15. Database Nodes Application Cluster Tracking Data is distributed evenly across nodes in a cluster using the Aerospike Smart Partitions™ algorithm. ■ Even distribution of ■Partitions across nodes ■Records across Partitions ■Data across Flash device ? Need to know Where each key is!
  • 16. func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) { newCluster := &Cluster{...} // start up cluster maintenance go routine newCluster.wgTend.Add(1) go newCluster.clusterBoss(policy) return newCluster, nil } func (clstr *Cluster) clusterBoss(policy *ClientPolicy) { defer clstr.wgTend.Done() Loop: for { select { case <-clstr.tendChannel: // tend channel closed break Loop case <-time.After(tendInterval): if err := clstr.tend(); err != nil { Logger.Warn(err.Error()) } } } // cleanup code goes here // close the nodes, ... } func (clstr *Cluster) Close() { if !clstr.closed.Get() { // send close signal to maintenance channel close(clstr.tendChannel) // wait until tend is over clstr.wgTend.Wait() } } Cluster Tracking Spawn Goroutine To Track Cluster Changes {
  • 17. func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) { newCluster := &Cluster{...} // start up cluster maintenance go routine newCluster.wgTend.Add(1) go newCluster.clusterBoss(policy) return newCluster, nil } func (clstr *Cluster) clusterBoss(policy *ClientPolicy) { defer clstr.wgTend.Done() Loop: for { select { case <-clstr.tendChannel: // tend channel closed break Loop case <-time.After(tendInterval): if err := clstr.tend(); err != nil { Logger.Warn(err.Error()) } } } // cleanup code goes here // close the nodes, ... } func (clstr *Cluster) Close() { if !clstr.closed.Get() { // send close signal to maintenance channel close(clstr.tendChannel) // wait until tend is over clstr.wgTend.Wait() } } Cluster Tracking On Intervals, Update Cluster Status {
  • 18. func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) { newCluster := &Cluster{...} // start up cluster maintenance go routine newCluster.wgTend.Add(1) go newCluster.clusterBoss(policy) return newCluster, nil } func (clstr *Cluster) clusterBoss(policy *ClientPolicy) { defer clstr.wgTend.Done() Loop: for { select { case <-clstr.tendChannel: // tend channel closed break Loop case <-time.After(tendInterval): if err := clstr.tend(); err != nil { Logger.Warn(err.Error()) } } } // cleanup code goes here // close the nodes, ... } func (clstr *Cluster) Close() { if !clstr.closed.Get() { // send close signal to maintenance channel close(clstr.tendChannel) // wait until tend is over clstr.wgTend.Wait() } } Cluster Tracking Broadcast Closing Of Cluster {
  • 19. func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) { newCluster := &Cluster{...} // start up cluster maintenance go routine newCluster.wgTend.Add(1) go newCluster.clusterBoss(policy) return newCluster, nil } func (clstr *Cluster) clusterBoss(policy *ClientPolicy) { defer clstr.wgTend.Done() Loop: for { select { case <-clstr.tendChannel: // tend channel closed break Loop case <-time.After(tendInterval): if err := clstr.tend(); err != nil { Logger.Warn(err.Error()) } } } // cleanup code goes here // close the nodes, ... } func (clstr *Cluster) Close() { if !clstr.closed.Get() { // send close signal to maintenance channel close(clstr.tendChannel) // wait until tend is over clstr.wgTend.Wait() } } Cluster Tracking Break the loop to clean up {
  • 20. How To Stream Back Data From Multiple Nodes
  • 21. Database Nodes Application Queries 1 Goroutine Per Node Queries are Scatter And Gather No Cursors Data Is Streamed Back Might Want To Continue With Other Nodes Errors Are Per Node
  • 23. Queries { Same buffered channel is used for all goroutines
  • 24. Queries { Errors are sent back on a separate channel
  • 25. 7 { Defer on all producers will ensure Close() is called at least once
  • 26. Queries Consumer Producer #N {Will not deadlock, all producers will return { The Above code will never panic, or block indefinitely: • defer on Execute() will ensure Close() is called at least once • When cancelled channel is closed, even if the Records channel is full and blocked, select will go through and return from goroutine
  • 27. Queries The Above code will never panic, or block indefinitely: • defer on Execute() will ensure Close() is called at least once • When cancelled channel is closed, even if the Records channel is full and blocked, select will go through and return from goroutine Consumer Producer #N {Will not panic, all producers have already stopped
  • 28. Consumption Pattern Consumer Fork #N {Supports numerous consumers Range on Channel, get either a Record or error Errors do not mean the stream has ended. They carry information about what went wrong, and where
  • 29. Take away • Channels are a good abstraction for data streaming • Easier to avoid deadlocks • Use the least number of channels and goroutines • Multiplex on demand • Goroutines are cheap, but not free • Pass channels throughout API, don’t ask for new ones
  • 30. How To Win Against The Garbage Collector
  • 31. Don’t Create Garbage • Avoid Memory Allocations • Might be trickier than you think! • Pool All Objects • Buffers • Hash Objects • Network Connections • Reusable Intermediate / Temporary Objects • Random Number Generators • sync.Pool is not ideal to pool long living objects • Integrated into GC, sweeps and deallocates objects too often • LIFO pools tend to do better regarding CPU cache • Channels for pool implementation still perform well though
  • 32. Don’t Reallocate Memory • Avoid Memory Allocations • Might be trickier than you think! • All following code snippets allocate memory: b := new(bytes.Buffer) longBuf := bytes.Repeat([]byte{32}, 100) // Allocation happens in Write to Grow the buffer b.Write([]byte{32}) // Re-allocation happens in Write to Grow the buffer b.Write(longBuf) // allocation happens inside Trim strings.Trim(" Trim this string ", " ") h := ripemd160.New() h.Write(data) // allocation happens inside Sum() h.Sum(nil) // Why? To support the general case func (d *digest) Sum(in []byte) []byte { // Make a copy of d0 so that caller can keep writing and summing. d := *d0
  • 34. Pools Indeterministic Pools are Resource Leaks You Haven’t Found Yet! * Please apply wisdom to the quip above *
  • 35. Pools • Make Pools Deterministic • Let User Decide About Parameters Per Use-Case • Document The Above! type BufferPool struct { pool [][]byte poolSize int pos int64 maxBufSize int initBufSize int mutex sync.Mutex } func (bp *BufferPool) Put(buf []byte) { if len(buf) <= bp.maxBufSize { ... } // buffer too big to go back into the pool } // a custom buffer pool with fine grained control over its contents // maxSize: 128KiB // initial bufferSize: 16 KiB // maximum buffer size to keep in the pool: 128K var bufPool = NewBufferPool(512, 16*1024, 128*1024) // SetCommandBufferPool can be used to customize the command Buffer Pool parameters to calib // the pool for different workloads func SetCommandBufferPool(poolSize, initBufSize, maxBufferSize int) { bufPool = NewBufferPool(poolSize, initBufSize, maxBufferSize) } Set & Enforce Limits for Pooled Buffers { { Set Sensible Defaults Let Users Tweak Per Use-Case
  • 36. type AtomicQueue struct { items chan interface{} } func NewAtomicQueue(size int) *AtomicQueue { return &AtomicQueue{ items: make(chan interface{}, size), } } func (aq *AtomicQueue) Offer(item interface{}) bool { // non-blocking send pattern select { case aq.items <- item: return true default: } return false } func (aq *AtomicQueue) Poll() interface{} { // non-blocking read pattern select { case item := <-aq.items: return item default: } return nil } Non-Blocking Sync’d Queues Using Channels Non-blocking Channel Read / Write Is Possible Non-Blocking { {
  • 37. Generic Pool Using Sync’d Queue
  • 38. How Does It Perform?
  • 39. Comparison vs C and Java 100% WRITE 100% READ 50% READ 50% WRITE C 261K 308K 273K JAVA 180K 280K 220K GO 306K 238K 276K Data Type: String of size 2000 Fastest Slowest Transactions Per Second
  • 40. Comparison vs C and Java 100% WRITE 100% READ 50% READ 50% WRITE C 299K 334K 307K JAVA 308K 339K 325K GO 338K 328K 330K Data Type: Integer (8 Bytes) Fastest Slowest Transactions Per Second