Commit a6119af
authored
The lane reads with the faster parser, and can send records it does not have to parse twice (#1352)
* The batch read can ask for records it does not have to parse twice
The lane can now send a record as a document rather than a JSON string, which
removes the reader's second parse. This is the reader side of that: batch_hget
asks for it, and the one consumer that still assumed a string accepts both.
`_decode_event_members` wanted a JSON array out of a string. An inline payload
arrives as the list itself, so it takes either -- and the call site stops
str()-ing the value, which would otherwise hand the decoder a Python repr that
no JSON parser accepts. That is the whole failure mode of switching a lane
under a reader, and it is why the shape is negotiated rather than assumed.
Scoped to batch_hget deliberately. scan_hash and hgetall keep the string shape,
so the marker read in `_locator_covers_pointed_ids` is untouched; widening it
means auditing those readers too.
Off unless MATRIXARK_LANE_INLINE_RECORDS is set. The readers accept both shapes
either way, so the switch can be measured and reverted without a deploy.
* The proxy can write its lane responses as msgpack frames
Groundwork for taking the lane off JSON entirely. The proxy already speaks
msgpack -- the engine and the index log both use rmp-serde -- so the encoder is
not new; what is new is a framing that can carry it.
Frames are LENGTH-PREFIXED, not delimited: a msgpack body can contain any byte
including the newline the text lane terminates on, so a reader that split on one
would cut a frame in half. Header is a magic byte plus a little-endian u32
length. The magic byte cannot begin a JSON line, so a reader handed the wrong
codec fails loudly instead of parsing garbage.
The codec is decided ONCE, from the environment the process was spawned with,
never per request. The lane is a single pipe carrying a stream of responses, so
a codec that changed partway would leave the reader mid-frame with no way back.
The spawner chooses; a spawner that sets nothing gets the JSON lines it always
got, which is every caller today.
This is INERT as it stands: nothing sets MATRIXARK_LANE_CODEC. The reader half
cannot be written until the stdio lane stops being opened in text mode -- Python
cannot read a length-prefixed frame from a text-mode pipe, and converting it
touches the request write and the stderr drain as well.
One finding is worth carrying forward from the tests: msgpack has a `bin` type
with no JSON equivalent, so decoding a frame into serde_json::Value fails with
"invalid type: byte array". A Python reader will get bytes where the text lane
gave it a str, for whatever the encoder chooses bin for. That has to be decided
before the frames carry traffic; it is not a framing question.
cargo test --bin matrixark_rust_proxy: 3 passed -- the text lane is still one
newline-terminated JSON line, a binary response is a frame whose header length
describes its body exactly and whose payload decodes to the same ok/op the text
lane would have sent, and the two codecs are distinguishable by their first byte.
* The lane reads with the faster parser where it is installed
Decoding the lane is where most of this process's CPU goes: a sampled profile
under load put raw_decode at 49.4% of gateway self time, with another 15.3% in
the lane reader itself. Measured on an identical corpus, 900 s per arm:
stdlib 28,047 gateway CPU ticks
orjson 25,302 gateway CPU ticks -9.8%
Proxy CPU was flat across the two arms (46,719 vs 48,726 ticks), which is the
control that matters: this is a Python-side change and should not move the other
process.
That is TOTAL CPU over equal-duration runs. An earlier note quoted -14.1% from
dividing the same totals by a message count taken from a mid-run sample; the
denominator is short and the ratio is inflated, so the total is the honest
figure.
One behaviour differs and accepting it is deliberate: integers beyond u64 decode
as floats rather than exact ints. JSON guarantees no integer precision past
2**53 -- JavaScript and most parsers lose it far earlier -- so a value that large
is already outside what an interoperable consumer round-trips. Every hash this
system stores is inside u64 and stays exact, which the tests pin. orjson's
JSONDecodeError subclasses the stdlib's, so the handlers around this call catch
it unchanged.
Optional by design: where orjson is not installed the stdlib parser is used and
nothing about the lane changes.
tools/test_the_lane_parser_reads_what_the_stdlib_reads.py: 5 passed on a host
with orjson 3.12.0 -- a full response reads identically to the stdlib, every u64
boundary value stays an exact int, a malformed line still raises what the
callers catch, and the one disagreement is asserted PER PARSER rather than as a
loose bound that would have held either way and pinned nothing. One test names
the parser it exercised, so a run on a host without orjson is visible rather
than silently green.1 parent d594c4a commit a6119af
4 files changed
Lines changed: 252 additions & 13 deletions
File tree
- crates/temporalstore-rust/src
- tools
Lines changed: 117 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
591 | 640 | | |
592 | 641 | | |
593 | 642 | | |
| 643 | + | |
594 | 644 | | |
595 | 645 | | |
596 | 646 | | |
| |||
647 | 697 | | |
648 | 698 | | |
649 | 699 | | |
650 | | - | |
651 | | - | |
| 700 | + | |
| 701 | + | |
652 | 702 | | |
653 | 703 | | |
654 | 704 | | |
| |||
704 | 754 | | |
705 | 755 | | |
706 | 756 | | |
707 | | - | |
708 | | - | |
| 757 | + | |
709 | 758 | | |
710 | 759 | | |
711 | 760 | | |
| |||
5573 | 5622 | | |
5574 | 5623 | | |
5575 | 5624 | | |
| 5625 | + | |
| 5626 | + | |
| 5627 | + | |
| 5628 | + | |
| 5629 | + | |
| 5630 | + | |
| 5631 | + | |
| 5632 | + | |
| 5633 | + | |
| 5634 | + | |
| 5635 | + | |
| 5636 | + | |
| 5637 | + | |
| 5638 | + | |
| 5639 | + | |
| 5640 | + | |
| 5641 | + | |
| 5642 | + | |
| 5643 | + | |
| 5644 | + | |
| 5645 | + | |
| 5646 | + | |
| 5647 | + | |
| 5648 | + | |
| 5649 | + | |
| 5650 | + | |
| 5651 | + | |
| 5652 | + | |
| 5653 | + | |
| 5654 | + | |
| 5655 | + | |
| 5656 | + | |
| 5657 | + | |
| 5658 | + | |
| 5659 | + | |
| 5660 | + | |
| 5661 | + | |
| 5662 | + | |
| 5663 | + | |
| 5664 | + | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
| 5685 | + | |
| 5686 | + | |
| 5687 | + | |
| 5688 | + | |
5576 | 5689 | | |
5577 | 5690 | | |
5578 | 5691 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
637 | 638 | | |
638 | 639 | | |
639 | 640 | | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
640 | 645 | | |
641 | 646 | | |
642 | 647 | | |
643 | 648 | | |
| 649 | + | |
644 | 650 | | |
645 | 651 | | |
646 | 652 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
22 | 48 | | |
23 | 49 | | |
24 | 50 | | |
| |||
2632 | 2658 | | |
2633 | 2659 | | |
2634 | 2660 | | |
2635 | | - | |
| 2661 | + | |
2636 | 2662 | | |
2637 | 2663 | | |
2638 | | - | |
| 2664 | + | |
2639 | 2665 | | |
2640 | 2666 | | |
2641 | | - | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
2642 | 2670 | | |
2643 | 2671 | | |
2644 | 2672 | | |
| |||
2656 | 2684 | | |
2657 | 2685 | | |
2658 | 2686 | | |
2659 | | - | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
2660 | 2694 | | |
2661 | 2695 | | |
2662 | | - | |
2663 | | - | |
2664 | | - | |
2665 | | - | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
2666 | 2703 | | |
2667 | 2704 | | |
2668 | 2705 | | |
| |||
3741 | 3778 | | |
3742 | 3779 | | |
3743 | 3780 | | |
3744 | | - | |
| 3781 | + | |
3745 | 3782 | | |
3746 | 3783 | | |
3747 | 3784 | | |
| |||
Lines changed: 83 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
0 commit comments