This repository was archived by the owner on Mar 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
update to new version of water_http #10849
Merged
msmith-techempower
merged 10 commits into
TechEmpower:master
from
HassanSharara:add-water-http-framework
Mar 10, 2026
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3609ee8
update to new version of water_http
HassanSharara ab13df7
replace json.rs file code
HassanSharara 09a4d00
change test name based on cfg input
HassanSharara 6a8dbc7
adding maintainers into benchmark_config.json
HassanSharara ec668c7
adding maintainers into benchmark_config.json
HassanSharara 8dbbbae
json changes
HassanSharara 970bf48
Merge remote-tracking branch 'upstream/master' into add-water-http-fr…
HassanSharara 48f83e0
remove unused files and add mini water_http server to the tests
HassanSharara 3e15ae0
change github rev for server crate
HassanSharara 7ae51d2
change default buffers size
HassanSharara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| use std::cell::RefCell; | ||
| use crate::models::Fortune; | ||
| // Assuming water_buffer crate exists | ||
| // use water_buffer::WaterBuffer as BM; | ||
|
|
||
| // Mocking the type for compilation demo | ||
| type WaterBuffer = Vec<u8>; | ||
|
|
||
| const INITIAL_VEC_CAPACITY: usize = 128; | ||
| const DEFAULT_SIZE: usize = 4048; | ||
| const MAX_BUFFER_SIZE: usize = 8192; // Allow some growth before discarding | ||
| const MAX_CACHED_BUFFERS: usize = 117; // Set to your test requirement | ||
|
|
||
| thread_local! { | ||
| static BUFFER_CACHE: RefCell<Vec<WaterBuffer>> = RefCell::new(Vec::with_capacity(INITIAL_VEC_CAPACITY)); | ||
| static FORTUNE_CACHE: RefCell<Vec<Vec<Fortune>>> = RefCell::new(Vec::with_capacity(INITIAL_VEC_CAPACITY)); | ||
| } | ||
|
|
||
| pub struct PooledBuffer { | ||
| inner: Option<WaterBuffer>, | ||
| } | ||
|
|
||
| pub struct FortunesPool { | ||
| inner: Option<Vec<Fortune>>, | ||
| } | ||
|
|
||
|
|
||
| impl PooledBuffer { | ||
| pub fn new() -> Self { | ||
| Self::with_capacity(DEFAULT_SIZE) | ||
| } | ||
|
|
||
| pub fn with_capacity(cap: usize) -> Self { | ||
| let buf = BUFFER_CACHE.with(|cache| { | ||
| let mut cache = cache.borrow_mut(); | ||
| if let Some(mut existing_buf) = cache.pop() { | ||
| // Assuming your WaterBuffer has a clear/reset method | ||
| existing_buf.clear(); | ||
| existing_buf | ||
| } else { | ||
| // Fallback to new allocation if cache is empty | ||
| WaterBuffer::with_capacity(cap) | ||
| } | ||
| }); | ||
|
|
||
| Self { inner: Some(buf) } | ||
| } | ||
|
|
||
| pub fn take_inner(&mut self) -> WaterBuffer { | ||
| self.inner.take().expect("Buffer already taken or dropped") | ||
| } | ||
|
|
||
| pub fn recycle(buf: WaterBuffer) { | ||
| // Use capacity() check to ensure we don't cache | ||
| // a buffer that grew to a massive size during one specific request | ||
| if buf.capacity() <= MAX_BUFFER_SIZE { | ||
| BUFFER_CACHE.with(|cache| { | ||
| let mut cache = cache.borrow_mut(); | ||
| if cache.len() < MAX_CACHED_BUFFERS { | ||
| cache.push(buf); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| impl FortunesPool { | ||
| pub fn new() -> Self { | ||
| Self::with_capacity(16) | ||
| } | ||
|
|
||
| pub fn with_capacity(cap: usize) -> Self { | ||
| let buf = FORTUNE_CACHE.with(|cache| { | ||
| let mut cache = cache.borrow_mut(); | ||
| if let Some(mut existing_buf) = cache.pop() { | ||
| // Assuming your WaterBuffer has a clear/reset method | ||
| existing_buf.clear(); | ||
| existing_buf | ||
| } else { | ||
| // Fallback to new allocation if cache is empty | ||
| Vec::with_capacity(cap) | ||
| } | ||
| }); | ||
|
|
||
| Self { inner: Some(buf) } | ||
| } | ||
|
|
||
| pub fn take_inner(&mut self) -> Vec<Fortune> { | ||
| self.inner.take().expect("Buffer already taken or dropped") | ||
| } | ||
|
|
||
| pub fn recycle(buf: WaterBuffer) { | ||
| // Use capacity() check to ensure we don't cache | ||
| // a buffer that grew to a massive size during one specific request | ||
| if buf.capacity() <= 16 { | ||
| BUFFER_CACHE.with(|cache| { | ||
| let mut cache = cache.borrow_mut(); | ||
| if cache.len() < 2000 { | ||
| cache.push(buf); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| #![allow(static_mut_refs)] | ||
|
|
||
|
|
||
| use std::io; | ||
| use std::fmt::Arguments; | ||
| use std::io::Write; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| use std::cell::UnsafeCell; | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
|
||
| thread_local! { | ||
| // We store the bytes directly in the Thread Local Storage (TLS) | ||
| // to ensure the reference stays valid for the life of the thread. | ||
| static CACHED_DATE: UnsafeCell<(u64, [u8; 29])> = UnsafeCell::new((0, [0u8; 29])); | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn get_date_fast() -> &'static str { | ||
| CACHED_DATE.with(|cell| { | ||
| unsafe { | ||
| let cache = &mut *cell.get(); | ||
| // 1. Use a fast duration check | ||
| let now = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .unwrap_unchecked() // Benchmark trick: avoid panic branches | ||
| .as_secs(); | ||
|
|
||
| if now != cache.0 { | ||
| cache.0 = now; | ||
| let date_str = httpdate::fmt_http_date(SystemTime::now()); | ||
| cache.1.copy_from_slice(date_str.as_bytes()); | ||
| } | ||
|
|
||
| // 2. Return a reference to the TLS memory directly. | ||
| // This is safe because the thread never dies during the benchmark. | ||
| std::str::from_utf8_unchecked(&cache.1) | ||
| } | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.