r/cpp • u/willycode1950 • May 04 '26
High-throughput log parsing (~500K lines/sec) in C++ without regex — looking for performance ideas
I’m building a log ingestion + parsing pipeline in C++ and trying to push throughput as far as possible.
Current setup:
- ~500K lines/sec
- custom tokenizer (no regex)
- string_view everywhere to avoid copies
- batch processing
- append-only write path
Next step:
I want to optimize the query side using:
- SIMD for substring search
- possibly precomputed token patterns
Questions:
- Best SIMD strategies for substring / token matching?
- Any experience with AVX2/AVX512 for log-like workloads?
- At what point does memory bandwidth become the bottleneck?
Also curious if anyone has benchmarked SIMD vs naive scan for log-style data.
Any pointers or war stories appreciated.
3
u/Agron7000 May 04 '26
500K lines/sec, and the line 2 bytes, or 26,000 bytes?
1 second on your machine could be 0.01 on my Epyc cpus.
Or more like 50,000K lines/second.
So please, provide these benchmarks in CPU/GPU/CUDA cycles, not in time.
2
u/dsmack6 May 10 '26
Few missing things, text encoding. Length of text per line, considering utf-8, is this average 75 bytes per line?
But one thing to confirm, regex has higher time complexity than plain text search, regex will take more than O(n), where n is the input size.
Others have commented instead of reading whole, chunk of bytes can be read, with offset.
Maybe multiple threads approach can do fine here.
6 threads searching for the keyword, starting with different offset.
So, individual threads are not starting from same index, rather they are working on different offset, time taken will be reduced.
Now, you want to complete all threads, or terminate other threads, when any of the thread meets target.
Remind me in one week. I will try with threading model different approaches, considering 500k lines, 125 bytes min average per line.
11
u/ILikeCutePuppies May 04 '26
Loading from disk into memory is most likely going to be the slowest thing. Chucking and doing it on multiple threads can help.
If you have control on the write side, writing less strings and using binary can help a huge amount. Common strings can be mapped to reduce size / read. A good compression choice can help with loading off disk. ie it can be faster to decompress and read a file than to read it off disk. Seriously SSD is thousands of times slower than ram.
Best thing though is to profile your unique situation.
4
u/anonymouspaceshuttle May 04 '26
Take a look at the https://github.com/variar/klogg -- it's blazingly fast for large log files.
1
u/schombert May 05 '26
There are lots of things you can do if you also control the format of the logs. Most obvious would be a binary format ... if that is not possible, then filling out fields to be a known length with spaces or separating them with characters that cannot occur inside them could enable faster parsing. Likewise, making each log entry a fixed size would allow skipping forwards in the file. If you can't make them a fixed size, marking the start/end of entries with some sequence that cannot occur within them would still allow skipping through the file by using those markers to resync.
1
u/twinkwithnoname May 05 '26
You haven't specified what the requirements are, so it's kinda hard to make any recommendations. For example, if you are dealing with random log files on the disk, using mmap is going to be a minefield. If you don't control the input format, you can't really get away from needing to let the user specify a regex. And so on...
1
u/Unhappy_Play4699 May 06 '26
I'm confused why some people are referring to GPU workloads when we are talking about logs, strings and tokens.
I'm also confused why people are talking about compression, when OP is likely referring to a general purpose log parser, where a dedicated format is unacceptable.
Multi-threading the parser will yield the biggest performance boost, depending on the size of the workload. Here it's important to find the right chunk size for the processing pipeline across hardware.
There is likely also no reason to use a third-party framework, since their purpose is to reduce generic pipeline orchestration complexity and not to optimize speed for a particular use-case.
2
u/Intrepid-Treacle1033 May 04 '26 edited May 06 '26
"...log ingestion + parsing pipeline..."
I have used flow graph design for importing massive datasets with great benefit. Not only performance also code maintenance benefits when new (always urgent) requirements pops up. Flow graph programing breaks down the "ingestion/pipeline" into smaller tasks and the lib has features to parallelize or not depending if threading overhead is worth it.
A cool feature is having a individual task in a graph be a offload to GPU, let the graph version 1 be CPU then with minor changes let v2 have task(s) be GPU offloaded.
I have use OneApi TBB task graph but there is also taskflow.
2
u/Ok_Chemistry_6387 May 09 '26
Profile.
1
u/gosh May 04 '26
For my search tool I have one "window" parser, a parser that moves a window over the text
Source: gd_parse_window_line.h
Tool: cleaner
1
u/yuehuang May 04 '26
I just learned about restrict keyword to help the improve auto vectorizing. Maybe it can help in your usage case.
1
u/nukethebees May 07 '26
Have you considered using custom allocators? Have you profiled the code to see where your time is being spent?
How is your data laid out?
1
u/pepejovi May 09 '26
Profile it. You're wasting your time otherwise.
1
u/[deleted] May 04 '26
[removed] — view removed comment