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

Core Unleashed Part II: Introduction to GobiesVM (and STM) @ RubyKaigi 2014

Core Unleashed Part II: Introduction to GobiesVM (and STM) @ RubyKaigi 2014

Szu-Kai Hsu (brucehsu)

September 18, 2014
Tweet

More Decks by Szu-Kai Hsu (brucehsu)

Other Decks in Programming

Transcript

  1. Cores Unleashed Part II
    Introducing GobiesVM (and STM)
    Szu-Kai Hsu (@brucehsu)

    View Slide

  2. Szu-Kai Hsu
    @brucehsu

    View Slide

  3. View Slide

  4. View Slide

  5. Previously on
    Cores Unleashed

    View Slide

  6. Concurrency/Parallelism
    in Ruby
    Concurrency Parallelism
    MRI/CRuby ✔ ✘
    Rubinius ✔ ✔
    JRuby ✔ ✔
    Topaz ✘ ✘

    View Slide

  7. CPU Usage

    View Slide

  8. CPU Usage - MRI

    View Slide

  9. CPU Usage - Rubinius

    View Slide

  10. CPU Usage - JRuby

    View Slide

  11. Thread Safety

    View Slide

  12. Thread Safety - MRI

    View Slide

  13. Thread Safety - Rubinius

    View Slide

  14. Thread Safety - JRuby

    View Slide

  15. Locks are bad
    “Beautiful Concurrency”, Simon Peyton Jones (2007)
    Taking too few locks
    Taking too many locks
    Taking the wrong locks
    Taking locks in the wrong order
    Error recovery
    Lost wake-ups and erroneous retries

    View Slide

  16. Software
    Transactional
    Memory

    View Slide

  17. GobiesVM
    https://github.com/brucehsu/GobiesVM

    View Slide

  18. GobiesVM in a nutshell
    Written in Go, utilizing native data structures and GC
    A Ruby subset derived from tinyrb
    Therefore uses a LEG parser instead of bison
    Stack-based VM which resembles YARV
    Minimal modification to existing code

    View Slide

  19. VM
    Coroutine Coroutine Coroutine Coroutine
    Bytecode
    Abstract Syntax Tree

    View Slide

  20. VM
    Coroutine Coroutine Coroutine Coroutine
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction
    Transaction

    View Slide

  21. BC_GETLOCAL, i
    BC_SEND, +, 1
    BC_PUTOBJ, 1
    BC_SEND
    BC_GETLOCAL
    Begin
    End
    Transaction
    bytecode
    stack
    ivar
    object-set
    rev

    View Slide

  22. Transactional Locking II
    Global Timestamp
    Transaction Transaction
    Local Timestamp Local Timestamp
    Read Set Read Set
    Write Set
    Write Set
    Transaction
    Local Timestamp
    Read Set
    Write Set

    View Slide

  23. Speculative Execution
    (READ)
    a
    Read Set
    Write Set
    a
    b
    c
    d
    e
    0x5566
    0x5567
    0x5568
    0x5569
    0x5570
    0x5566
    10

    View Slide

  24. Speculative Execution
    (WRITE)
    a+=1
    Read Set
    Write Set
    a
    b
    c
    d
    e
    0x5566
    0x5567
    0x5568
    0x5569
    0x5570
    0x5566
    a 11
    10
    0x5566

    View Slide

  25. Speculative Execution
    (READ-AFTER-WRITE)
    a
    Read Set
    Write Set
    a
    b
    c
    d
    e
    0x5566
    0x5567
    0x5568
    0x5569
    0x5570
    0x5566
    a 11

    View Slide

  26. Combined Object-Set
    RObject
    Object-Set
    Read-Set

    View Slide

  27. Combined Object-Set
    RObject
    Object-Set
    RObject
    Write-Set

    View Slide

  28. Validation
    Read Set
    Write Set
    Global Timestamp
    Check rev of object
    rev > local_timestamp: object has been modified
    Acquire locks of objects to be modified
    Abort on failure
    Increments by one

    View Slide

  29. Commit
    RObject
    class
    ivar
    methods
    RObject
    class
    ivar
    methods
    Copy to original

    View Slide

  30. – Torvalds, Linus (2000-08-25)
    Talk is cheap.
    Show me the code

    View Slide

  31. Live Demo

    View Slide

  32. What’s next?

    View Slide

  33. Better parser
    Go provides goyacc for parsing
    But we have to do lexical scanning ourselves.
    https://sourcegraph.com/blog/multi-language-lexer-
    and-scanner-for-go

    View Slide

  34. Better syntax support
    What we don’t have now:
    Conditional statements
    Class/Method definitions
    Double-quoted strings
    And more…

    View Slide

  35. Atomic operations
    New syntax: atomic block
    Make every statement atomic

    View Slide

  36. Production-ready (perhaps)
    Rubygems
    Native extension interface
    Go can work with C code, but not thread-safe
    Comprehensive exceptions

    View Slide

  37. Optimizations
    Performance!
    Performance!!
    Transaction length

    View Slide

  38. GobiesVM
    https://github.com/brucehsu/GobiesVM

    View Slide

  39. Thanks for your attention
    Any questions?

    View Slide