steFaiz opened a new pull request, #26:
URL: https://github.com/apache/paimon-full-text/pull/26

   This PR contains several optimizations & fix (Please tell me to split them 
if necessary)
   
   ## Expose build thread num & memory limit through config
   Currently thread num is hard-coded as 1 and memory limit is hard coded as 50 
MB. This is very slow in real tasks.
   
   **Measured.** 1,000,000 documents, 2.85 GB of text, jieba tokenizer with 
positions,
   local disk:
   
   | Threads | Memory budget | Build time | CPU time |
   |---|---|---|---|
   | 1 | 50 MB (previous behaviour) | 247 s | 275 s |
   | 4 | 200 MB | 67.5 s | 291 s |
   
   ## Release Java Heap Buffer
   `JavaInput::pread` and `JavaOutput::write_all` create one `byte[]` per 
callback and never delete the local reference. These java heap memory will be 
occupied during the whole query!
   
   **Measured.** Real 368 MB index, a new reader per thread running four 
queries that
   read 100 MB in total (largest single read 35 MB):
   
   | Threads | `-Xmx` | Before | After |
   |---|---|---|---|
   | 1 | 2 GB | ok | ok |
   | 1 | 96 MB | `OutOfMemoryError: Java heap space` | ok |
   | 4 | 256 MB | `OutOfMemoryError: Java heap space` | ok |
   
   ## A lightweight cache for file ranges
   This is introduced for some repeated tokens in query, for exmaple, consider 
this query:
   ```
   hello I am a paimoner
   ```
   the tokens generated by JIEBA will be:
   ```
   'hello', ' ', 'I', ' ', 'am', ' ', 'a', ' ', 'paimoner'
   ```
   There will be 4 spaces which will be repeated queried by tantivy. In 
original tantivy, files are `mmap`ed in to memory, but in paimon-full-text, 
these index info will be repeated read from file and queried.
   
   Reads larger than the block size are registered by (archive offset, length) 
as a weak reference. A later read of the same range reuses the buffer while 
Tantivy still holds it; otherwise it is read again. Nothing is retained after 
Tantivy drops the bytes, so this never adds memory, and no capacity or eviction 
policy is needed.
   
   **Measured.** `match_phrase` with a 25-word English sentence, one cold 
reader per
   shard, shards of ~3.5 GB (1,000,000 documents, 13 segments, jieba) on a 
FUSE-mounted
   distributed filesystem, Java callback input:
   
   | | Before | After |
   |---|---|---|
   | Bytes read per shard | 11.4 GB | 0.63 GB |
   | Latency, 1 shard at a time (median of 6) | 5.3 s | 1.25 s |
   | Latency, 4 shards concurrently (median of 8) | 8.6 s | 1.4 s |
   | Peak process RSS, 1 shard at a time | 10.8 GB | 1.85 GB |
   | Peak process RSS, 4 shards concurrently | 18.0 GB | 3.8 GB |
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to