Skip to content

Commit

Permalink
increase output buffer size slower after 500mb
Browse files Browse the repository at this point in the history
this should help lowering the memory footprint
  • Loading branch information
sni committed Feb 6, 2025
1 parent f6476ce commit dc3bc1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/OutputBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ void OutputBuffer::needSpace(unsigned len)
{
unsigned s = size();
unsigned needed = s + len;
while (_max_size < needed) // double, until enough space
_max_size *= 2;
while (_max_size < needed) {
// increase until enough space
// double untill 500MB
if(_max_size < 500 * 1024 * 1024) {
_max_size *= 2;
} else {
// increase by 25% afterwards
_max_size += (_max_size / 4);
}
}

_buffer = (char *)realloc(_buffer, _max_size);
_writepos = _buffer + s;
Expand Down
2 changes: 1 addition & 1 deletion src/OutputBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string>
using namespace std;

#define INITIAL_OUTPUT_BUFFER_SIZE 1
#define INITIAL_OUTPUT_BUFFER_SIZE 1024

#define RESPONSE_CODE_OK 200
#define RESPONSE_CODE_INVALID_HEADER 400
Expand Down

0 comments on commit dc3bc1a

Please sign in to comment.