Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE - Experimental Java Native Cached Write Batch #13115

Closed

Commits on Nov 15, 2024

  1. wip of native write batch

    not working yet - invalid link
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    e29730f View commit details
    Browse the repository at this point in the history
  2. I am an idiot.

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    3df3191 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    69d94f4 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e0daab8 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d5070f7 View commit details
    Browse the repository at this point in the history
  6. Pause wip

    comments there for what to pick up on
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    5e361f1 View commit details
    Browse the repository at this point in the history
  7. Add Put with CF, fix test.

    rhubner authored and alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    ba3e641 View commit details
    Browse the repository at this point in the history
  8. Add JMH test for write batch.

    rhubner authored and alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    56d5964 View commit details
    Browse the repository at this point in the history
  9. Update jmh benchmarks for native write batch

    Extend original native write batch jmh tests to help us compare various write batch implementations.
    So-far-unused WriteBatchJavaCMem as placeholder for alternative implementation of native write batch.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    141d306 View commit details
    Browse the repository at this point in the history
  10. WriteBatch Java API Performance baseline

    - Finish making first prototype WriteBatchJavaNative work for put()
      - buffers put() requests on Java side
      - applies batched put() requests to C++ write_batch buffer on flush()
      - RocksDB.write(options, WriteBatchJavaNative) applies batch to DB
    - Clean up JMH performance tests for WriteBatchJavaNative vs existing WriteBatch
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    e417588 View commit details
    Browse the repository at this point in the history
  11. WriteBatchJavaNative UnsupportedOperationException

    Give this prototype method UnsupportedOperationException on unimplemented methods so that we donm’t waste time investigating why jmh tests that call no-ops
    are so fast :-(
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    abf3913 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    5e4876b View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    5dbc3e9 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    f6eb81a View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    7c9343b View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    14c42b1 View commit details
    Browse the repository at this point in the history
  17. Direct buffer version of write batch java native

    Pass contents in direct ByteBuffer (WriteBatchJavaNativeDirect)
    Refactor out from byte[] version (WriteBatchJavaNativeArray)
    
    Fix to pre-expand buffers by size rather than re-run insertion on overflow
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    7c37861 View commit details
    Browse the repository at this point in the history
  18. jmh writebatch “don’t write the batch to DB” option

    “flushToDB” option used for stripping out the cost of the DB write at the end.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    4f171a8 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    02ac2ef View commit details
    Browse the repository at this point in the history
  20. Java write batch - defer creation of native

    Refactor array/direct native variants into a single class with different static factories.
    Add native C++ support methods for creating the write batch on a write() if it doesn’t already exist.
    Add similar flush methods for creating the write batch on a flush() if it doesn’t already exist.
    Remove expansion on Java side - buffer is the requested size, behaviour should be to fill that and then flush, OR (TODO) to bypass it entirely (just make diret JNI calls to writebatch as before) for big writes
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    b90a3fe View commit details
    Browse the repository at this point in the history
  21. java native write batch - native methods private

    Refactored previously to remove subclass. So protected methods can now be private.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    513f7e4 View commit details
    Browse the repository at this point in the history
  22. java native write batch - handle big put()s

    Bypass the java side buffer when put()sare bigger than 50% of the buffer size - which is controlled at constructor time.
    Doing a big Put() to this kind of write batch causes the buffer to be flushed (if there is anything in it) and then the Put() is performed directly over the JNI to C++
    Note that the WriteBatch on the C++ side is created lazily; this may be on a flush of a batch (buffer is full), or it may be on the write of a batch to a DB, or it may be on a bypass write such as the one implemented here.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    131c1f9 View commit details
    Browse the repository at this point in the history
  23. java native write batch - re-order custom layout

    A quick step before trying to replicate the layout to the level at which it can be directly memory copied.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    1bc7551 View commit details
    Browse the repository at this point in the history
  24. java native write batch - change to C++ encoding

    Pick up an efficient varint encoder from the interwebs
    Rewrite the encoding using that
    
    TODO - the C++ side, so all failing at present
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    603f610 View commit details
    Browse the repository at this point in the history
  25. Copy C++ format write batch from Java

    Java-side write batch has same format as C++, so can be memcpy-ed (in theory).
    In practive it can be assign()-ed to an empty write batch in a single copy.
    
    In the case of an existing write batch, the std::string representation does not allow us to append() in 1-copy (because we have to copy into a std::string first to call append()) so we adapt what we did before, and step through the Java representation, calling Put() with  Slices manufactured from the entries in the buffer. I think it is OK..
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    99d04d7 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    c356592 View commit details
    Browse the repository at this point in the history
  27. Re-make jmh tests consistent w/ native write batch

    Last few changes to native write batch have modified the API slightly. Some of the test configuration is unnecessary or wrong, and the calls for creation are all part of a single class. Update these appropriately.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    8286f56 View commit details
    Browse the repository at this point in the history
  28. java native write batch fix varint32

    Translation of Varint32 I had stolen was bugged.
    Probably my translation is the problem.
    Use instead the slightly less efficient but more readable and adequately fast version.
    Fix the Varint32 test(s).
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    79dfe64 View commit details
    Browse the repository at this point in the history
  29. java native batch - bulk copy on creating write()

    We should have added this optimization as part of the last set of changes.
    When we are calling write(), and the batch has not been created on the native/C++ side,
    we can use the same optimization as in flush, to wit:
    `WriteBatchInternal::SetContents(this, slice)` directly (via Append())
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    327afa7 View commit details
    Browse the repository at this point in the history
  30. New test was incorrect.

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    7cf4a7e View commit details
    Browse the repository at this point in the history
  31. Update results

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    c5ea199 View commit details
    Browse the repository at this point in the history
  32. Repair build config files

    Update lists of files includes in builds and tests to correctly list the ones for the native write batch changes.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    90c320f View commit details
    Browse the repository at this point in the history
  33. Add method to bulk append part of batch as a slice

    WriteBatchInternal::AppendContents allows us to append extra batch entries in bulk in a single copy, without the complexity of iteration and individual elements.
    Hope for improved performance.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    8ce88ec View commit details
    Browse the repository at this point in the history
  34. Remove obsolete code

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    c16b604 View commit details
    Browse the repository at this point in the history
  35. Add jmh run for WriteBatchInternal::AppendContents

    WriteBatchInternal::AppendContents is not noticeable better performing, but it is cleaner and we have saved ourselves some code.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    6789ff9 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    dcf11ad View commit details
    Browse the repository at this point in the history
  37. More benchmarks run

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    99013f8 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    0a94207 View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    2d3c608 View commit details
    Browse the repository at this point in the history
  40. More results.

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    7a833d6 View commit details
    Browse the repository at this point in the history
  41. Format fixes

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    c6d885e View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    0c14efb View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    8d3e486 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    65f282c View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    eb66c81 View commit details
    Browse the repository at this point in the history
  46. 2 performance fixes Java write batch

    build an allocator into the write batch so that it can recycle bytebuffers rather than continually re-allocating them.
    
    When passing a direct bytebuffer, slice() it first before passing over JNI. This has a huge performance win, there is something (probing, or god forbid, copying) going on when we get the buffer from JNI.
    
    We still need to byte arrays, which are by far the slowest.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    eacfed7 View commit details
    Browse the repository at this point in the history
  47. More JNI write batch performance fixes

    Second instance of - When passing a direct bytebuffer, slice() it first before passing over JNI
    Use critical section instead of env->GetByteArrayElements to avoid a copy of a potentially very large array, only part of which we may need. It has drawbacks, but for demonstrating performance and working round the byte[] version’s performance bug,
    it is invaluable.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    135382a View commit details
    Browse the repository at this point in the history
  48. words

    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    ebbdbb7 View commit details
    Browse the repository at this point in the history
  49. Revise write batch jmh operations

    1 operation now consists of writing a single batch of the required size.
    Performance is how many batches are written per second.
    alanpaxton committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    d36026e View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    b4cfcb8 View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    0d409b9 View commit details
    Browse the repository at this point in the history