$30 off During Our Annual Pro Sale. View Details »

The Rough Guide to Java RPC Frameworks

The Rough Guide to Java RPC Frameworks

Distributed computing is here to stay, and more and more Java developers are exploring the ecosystem of available remote procedure call (RPC) frameworks for building distributed applications or microservices. However, which RPC framework suits you best?

This presentation will cover the characteristics and usage of different RPC frameworks (e.g. Netty, gRPC, Aeron/SBE, KryoNet, Apache Thrift) via a practical real-life use case. For this presentation, the use case will be providing remote polyglot access to Infinispan, which is an in-memory data grid platform from Red Hat. Since 2010 it has offered remote access via a custom protocol. During this talk we will explore how to re-implement this custom protocol using multiple RPC frameworks. So, you will be to see first hand how these RPC frameworks behave, the necessary steps to get started with them, and learn how you can apply them in your project.

Galder Zamarreño

March 14, 2018
Tweet

More Decks by Galder Zamarreño

Other Decks in Programming

Transcript

  1. THE ROUGH GUIDE TO
    JAVA RPC FRAMEWORKS
    1 4 t h M a r c h 2 0 1 8
    G A L D E R Z A M A R R E Ñ O A R R I Z A B A L A G A
    1
    @ g a l d e r z

    View Slide

  2. D I S T R I B U T E D C O M P U T I N G
    I S H E R E TO S TAY . . .
    2
    @ g a l d e r z

    View Slide

  3. SCALABILITY
    run multiple instances to meet demand
    ELASTICITY
    scale up/down without downtime
    RESILIENT
    handle failure transparently
    SPEED OF CHANGE
    evolve parts independently
    DISTRIBUTED COMPUTING GIVES US...
    3
    flickr.com/photos/ministerio_tic/6812435353
    @ g a l d e r z

    View Slide

  4. 4
    static.pexels.com/photos/158163/clouds-cloudporn-weather- flickr.com/photos/aidanwojtas/34885389822

    View Slide

  5. COMPONENTS TALKING TO EACH OTHER
    e.g. server / server
    A A X Y
    e.g. client / server
    5
    @ g a l d e r z

    View Slide

  6. 6
    LEARN HOW COMPONENTS
    CAN TALK TO EACH OTHER
    OVER THE NETWORK
    @ g a l d e r z

    View Slide

  7. 7
    CONSIDERING OTHER LANGUAGES TOO...
    @ g a l d e r z

    View Slide

  8. W H Y A M I TA L K I N G
    A B O U T T H I S ?
    8
    @ g a l d e r z

    View Slide

  9. @galderz
    s i n ce 2 0 0 6
    S O F T WA R E
    E N G I N E E R
    co m m u n i t y a n d
    c l i e n t / s e r ve r l e a d
    I N F I N I S PA N
    C O - F O U N D E R ( 2 0 0 9 )
    M U D K I P R O C K S !
    9
    @ g a l d e r z

    View Slide

  10. D ATA C A C H E
    T E M P O R A R Y D ATA
    expensive to retrieve
    or hard to calculate
    data that needs surviving
    in case of failure
    E V E N T B R O K E R
    & A N A L Y T I C S
    I N - M E M O R Y S TO R E
    D I S T R I B U T E D
    key / value store
    linearly scalable
    db, cassandra, file...etc
    C A N P E R S I S T
    10
    @ g a l d e r z

    View Slide

  11. to distribute data around
    pluggable architecture with these as main options
    internal use only
    S E R V E R - TO - S E R V E R O V E R J G R O U P S
    U D P O R TC P
    U S E R S O N L Y S E E C O N F I G U R AT I O N
    11
    @ g a l d e r z

    View Slide

  12. 12
    EMBEDDED
    2009
    REMOTE
    2010
    @ g a l d e r z

    View Slide

  13. HTTP 1.x REST API
    G E T / { c a c h e N a m e } / { c a c h e K e y }
    P U T / { c a c h e N a m e } / { c a c h e K e y }
    D E L E T E / { c a c h e N a m e } / { c a c h e K e y }
    13
    @ g a l d e r z

    View Slide

  14. GOOD
    H T T P 1 . x R E S T A P I
    easy to learn, easy to debug
    D E S C R I P T I V E
    easily accessible from any language
    U N I V E R S A L L Y A C C E S S I B L E
    BAD
    H T T P 1 . x R E S T A P I
    text data takes much more bandwidth
    parsing expensive
    I N E F F I C I E N T P R O T O C O L
    as a result of sending parallel requests
    C O N N E C T I O N E X H A U S T I O N
    processing a request needs to finish before
    starting with next one
    P R O C E S S O N E R E Q U E S T AT T I M E
    14
    @ g a l d e r z

    View Slide

  15. BINARY PROTOCOL
    Y O U C A N W R I T E H E R E
    H O T R O D
    less bytes sent, zig-zag encoding
    B E T T E R N E T W O R K E F F I C I E N C Y
    avoid extra hoops
    H A S H I N G - AWA R E R O U T I N G
    automatically adjust topologies
    as nodes join or leave
    D Y N A M I C TO P O L O G I E S
    15
    @ g a l d e r z

    View Slide

  16. NETTY
    used to develop protocol servers and clients
    N I O C L I E N T / S E R V E R F R A M E W O R K
    allows for clear separation of concerns
    F L E X I B L E & E X T E N S I B L E E V E N T M O D E L
    simplifies and streamlines developing
    TCP or UDP servers
    E A S Y N E T W O R K P R O G R A M M I N G
    16
    @ g a l d e r z
    P O W E R I N G O U R B I N A R Y P R O TOCO L

    View Slide

  17. GOOD
    N E T T Y
    can handle any type of load
    P E R F O R M A N C E & S C A L A B I L I T Y
    e.g. heavily used at Apple
    H U G E C O M M U N I T Y
    keep your dependencies simple
    N O A D D I T I O N A L D E P E N D E N C I E S
    BAD
    N E T T Y
    mitigated with binary serialization libraries
    M A N U A L E N C O D I N G
    17
    @ g a l d e r z

    View Slide

  18. IMMATURE
    apache thrift - incubator version 0.2
    message pack - version 0.3
    BOUNDED
    BY THE TOOL
    limit yourself to languages supported by tool
    L E A R N M O R E
    18
    LACKING STREET
    CREDIBILITY
    google protocol buffers
    NETWORK LAYER
    NOT COVERED
    you still have to write all the network layer
    in each target language
    2010: PORTABLE SERIALIZATION
    @ g a l d e r z

    View Slide

  19. L A G S B E H I N D
    B U T P O P U L A R
    not as much attention as binary
    particularly for those using
    languages not covered by binary
    1 1 N E W V E R S I O N S
    1 2 N E W O P E R AT I O N S
    both fixes and new operations
    total of 32 operations
    java client is reference one,
    others always lagging a bit behind
    J AVA , C + + / C # , N O D E
    19
    BINARY HTTP
    8 YEARS ON...
    @ g a l d e r z

    View Slide

  20. A D D I N G
    N E W O P E R AT I O N S
    R E Q U I R E S
    A L O T O F E F F O R T
    20
    @ g a l d e r z

    View Slide

  21. MORE OPERATIONS
    MORE QUICKLY
    MORE EFFICIENTLY
    MAINTAIN SAME
    PERFORMANCE
    L E A R N M O R E
    21
    MODERNISING INFINISPAN REMOTE
    @ g a l d e r z

    View Slide

  22. simple and easy to use
    backed by years of experience with Stubby
    can work across languages
    S I M P L E & I D I O M AT I C
    P E R F O R M A N T & S C A L A B L E
    I N T E R O P E R A B L E & E X T E N S I B L E
    22
    @ g a l d e r z

    View Slide

  23. message definition
    portable message encoding mechanism, supporting:
    C++, Objective-C, PHP, Python, Ruby, Node.js, Go, C#,
    Java
    binary protocol - no more text
    native stream support
    stream multiplexing - single connection
    header compression - saves more bandwidth
    I D L
    P R O TO B U F 3
    H T T P / 2
    23
    @ g a l d e r z

    View Slide

  24. L E T ' S S E E T H I S . . .
    24
    @ g a l d e r z

    View Slide

  25. HASH-AWARE ROUTING
    Y O U C A N W R I T E H E R E
    W I T H G R P C
    configurable
    C L I E N T - S I D E L O A D B A L A N C I N G
    so that SubchannelPicker can do its job
    A D D K E Y A S H T T P H E A D E R
    inspects HTTP headers and can decide
    which channel to send data through
    S U B C H A N N E L P I C K E R
    25
    @ g a l d e r z

    View Slide

  26. T I T L E
    S T R E A M R E C O R D I N G
    M O N I TO R & D E B U G
    archive recording
    for later replay
    designed so that internal state
    can be observed at runtime
    Apache License 2.0
    O P E N S O U R C E
    M E S S A G E
    T R A N S P O R T
    H I G H P E R F O R M A N C E
    UDP and IPC transports
    highest throughput with lowest
    and most predictable latency
    schema driven
    source code generation
    J AVA , C + + , . N E T
    26
    @ g a l d e r z

    View Slide

  27. T I T L E
    S I N G L E W R I T E R
    U N S H A R E D S TAT E
    apply it everywhere
    prefer it where possible
    avoid unnecessary copies
    AV O I D C O P I E S
    G A R B A G E F R E E
    S M A R T B ATC H I N G
    in the message path
    in the message path
    N I O & L O C K - F R E E
    27
    in steady state running
    @ g a l d e r z

    View Slide

  28. AERON ARCHITECTURE
    Y O U C A N W R I T E H E R E
    p u b l i s h e r s s e n d m e s s a g e s
    t h a t S u b s c r i b e r s co n s u m e
    U N I D I R E C T I O N A L
    U D P , I P C , I n f i n i b a n d
    d e t a i l s h a n d l e d by
    m e d i a d r i ve r
    M E D I A - S P E C I F I C
    m e d i a d r i ve r a s s e p a ra t e
    p r o ce s s t o avo i d c l i e n t s i d e G C
    S E PA R AT E P R O C E S S
    28
    @ g a l d e r z

    View Slide

  29. L E T ' S S E E T H I S . . .
    29
    @ g a l d e r z

    View Slide

  30. WHEN TO USE WHAT?
    Y O U C A N W R I T E H E R E
    you get more control but more code to write
    A E R O N I S L O W L E V E L ( ~ N E T T Y )
    payload & network code generated for multiple languages
    A E R O N I S P O R TA B L E ( ~ g R P C )
    congested networks or clients go across a WAN
    I F TC P N E E D E D : N E T T Y o r g R P C
    aeron specifically designed for this - no TCP support
    I F C L I E N T S I N L A N : A E R O N
    data centre workloads, e.g. P2P nodes within a LAN
    A E R O N G O O D F O R S E R V E R - S E R V E R
    beats even commercial offerings
    A E R O N F O R U L T I M AT E P E R F O R M A N C E
    C O M P A R I S O N
    30
    @ g a l d e r z

    View Slide

  31. ”THE BEST TEMPLATE EVER”
    Y O U C A N W R I T E H E R E
    A company is an association or collection of individuals, whether natural persons, legal
    persons, or a mixture of both. Company members share a common purpose and unite in
    order to focus their various.
    31
    github.com/benalexau/rpc-bench
    @ g a l d e r z

    View Slide

  32. ”THE BEST TEMPLATE EVER”
    Y O U C A N W R I T E H E R E
    A company is an association or collection of individuals, whether natural persons, legal
    persons, or a mixture of both. Company members share a common purpose and unite in
    order to focus their various.
    32
    github.com/benalexau/rpc-bench
    @ g a l d e r z

    View Slide

  33. LESSONS LEARNT (SO FAR)
    Y O U C A N W R I T E H E R E
    what is the lowest common denominator?
    N O N E E D C O D E G E N E R AT E D I N A L L L A N G U A G E S
    aeron is a strong candidate but we don't control clients
    F O R I N F I N I S PA N , P R O B A B L Y G R P C
    33
    @ g a l d e r z
    C or a more typesafe language that can create C bindings (e.g. Haskell?)
    if JNI goes away (project panama), maybe Java can call into C
    J AVA A N D C S H O U L D B E E N O U G H

    View Slide

  34. C R E D I T S
    34
    @ g a l d e r z

    View Slide

  35. THANK YOU
    i n f i n i s p a n . o r g
    I N F I N I S PA N
    n e t t y . i o
    N E T T Y
    g r p c . i o
    G R P C
    g i t h u b . co m / r e a l - l o g i c / a e r o n
    A E R O N
    35
    g i t h u b . co m / g a l d e r z / r p c s
    @ g a l d e r z

    View Slide