diffusion anatomyofahigh-performancejavaserver philipaston · diffusion - anatomy of a...

21
Diffusion Anatomy of a high-performance Java server Philip Aston Docklands.LJC, November 2016 1

Upload: others

Post on 19-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

DiffusionAnatomy of a high-performance Java server

Philip Aston

Docklands.LJC, November 2016

1

Page 2: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Philip Aston

Product Architect at Push Technology• [email protected]

Ex-BEA, ex-Oracle• WebLogic Server / Coherence / Oracle Event Processing• Professional Oracle WebLogic Server (Wrox 2009)• J2EE Performance Testing (Expert Press 2002)

The Grinder

2

Page 3: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

The Product Slide

Push Technology

• Real-time data distribution for web, mobile, and IoT

Diffusion• Real-time messaging at scale• Java server• Android, iOS/OS X, JavaScript, .NET, C, and Java SDKs

Reappt

• Diffusion As A Service on IBM BlueMix and AppDirect

3

Page 4: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

What's coming up?

High Performance Broadcast, in Java

Publish and Subscribe

4

Page 5: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

High Performance Broadcast

5

Page 6: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Applied "Mechanical Sympathy"

Martin Thompson

mechanical-sympathy mail list

6

Page 7: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

The big picture

7

Page 8: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Actor - a processing pa ern

8

Page 9: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Output processing

9

Page 10: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Benefits

Simple sequential programming

• Non-thread safe data structures• Consistent order

Memory hierarchy friendly

• Hot threads bound to single cores• Thread-exclusive data structures

Parallel• Scales across cores and sockets• Pipelining

10

Page 11: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Java NIO Constraints

Selector• Selected key set is not thread-safe• Easiest if registration for CONNECT, ACCEPT, READ, WRITE,and close all occur on a single thread

Channel• For consistent, ordered processing

• Read from single thread• Write from a single thread

11

Page 12: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Selector Actor

12

Page 13: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Benchmark results

13

Page 14: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Inter-thread communication

14

Page 15: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Choosing a concurrent, in-memory queue

JDK options don’t cut it• ArrayBlockingQueue

• Single lock synchronises producers and consumers• ConcurrentLinkedQueue

• allocates for each offer• is unbounded

15

Page 16: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

JCTools

Nitsan Wakart

• PsyLobSaw blog• JCTools

16

Page 17: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

JCTools

MpscArrayQueue

• Multi-producer, single consumer, bounded queue• Lock-free

Details• Separate consumer and producer fields

• False sharing avoidance• Optimised memory barriers

• Producers use CAS to update fields• Consumer uses Fast Flow method

See Lock Free Queues or Queue Evolution: from 10M to 470M ops/sec for much more.

17

Page 18: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Publish and Subscribe

18

Page 19: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Diffusion pub/sub - it's different

1 Value-based interface• Developers focus on application data, not messages• SDKs provide idiomatic native API

2 Stateful topics - the inverted data grid• The server maintains current value for each topic• Clients synchronised with topic value on subscription• Deltas follow

3 Interest-based subscription• Clients provide topic selectors• Server matches selectors against topics and authorisation

19

Page 20: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Copyright Push Technology 2016

Take aways

1 Event-oriented / non-blocking throughout2 Threads aligned to processing flow

• Separate input and output processing• Minimal inter-thread communication via queues

3 Thread-exclusive data• Sessions partitioned across threads• Processing batched where possible• Global state shared as immutable snapshots

http://docs.pushtechnology.com/http://developer.reappt.io/docs/index.html

20

Page 21: Diffusion Anatomyofahigh-performanceJavaserver PhilipAston · Diffusion - Anatomy of a high-performance Java server Author: Philip Aston Created Date: 11/23/2016 9:36:58 AM

Thank you - Any Questions?

21