Skip to content

Commit d1b22ea

Browse files
committed
Adjust buffer sizes.
1 parent 4977e00 commit d1b22ea

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/apib_io_basic.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void ConnectionState::SendWrite() {
256256

257257
int ConnectionState::singleRead(struct ev_loop* loop, ev_io* w, int revents) {
258258
io_Verbose(this, "I/O ready on read path: %i\n", revents);
259-
const size_t len = readBufSize - readBufPos_;
259+
const size_t len = kReadBufSize - readBufPos_;
260260
assert(len > 0);
261261

262262
size_t readCount;

src/apib_iothread.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ namespace apib {
3434
http_parser_settings IOThread::parserSettings_;
3535
static std::once_flag parserInitalized;
3636

37-
ConnectionState::ConnectionState(int index, IOThread* t) {
38-
index_ = index;
37+
ConnectionState::ConnectionState(int index, IOThread* t) : index_(index) {
3938
keepRunning_ = 1;
4039
t_ = t;
41-
readBuf_ = (char*)malloc(readBufSize);
40+
readBuf_ = new char[kReadBufSize];
4241
}
4342

4443
// TODO memory leak -- COnnectionStates are freed when threads exit but not
4544
// when they just close. Think of a way to handle this...
46-
ConnectionState::~ConnectionState() { free(readBuf_); }
45+
ConnectionState::~ConnectionState() { delete[] readBuf_; }
4746

4847
int ConnectionState::httpComplete(http_parser* p) {
4948
ConnectionState* c = (ConnectionState*)p->data;

src/apib_iothread.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ class ConnectionState {
173173
static int httpComplete(http_parser* p);
174174

175175
private:
176-
static constexpr int readBufSize = 512;
177-
static constexpr int writeBufSize = 1024;
176+
// The size of the buffer to read from when calling read()
177+
// or SSL_read()
178+
static constexpr int kReadBufSize = 8192;
179+
// In the event that connecting a socket fails, we will wait
180+
// for this time, in seconds, before trying again.
181+
// Nevertheless, if this ever gets used then the benchmark
182+
// is pretty much ruined anyway...
178183
static constexpr double kConnectFailureDelay = 0.25;
179184

180185
void addThinkTime();
@@ -195,7 +200,7 @@ class ConnectionState {
195200
static void writeReady(struct ev_loop* loop, ev_io* w, int revents);
196201
static void thinkingDone(struct ev_loop* loop, ev_timer* t, int revents);
197202

198-
int index_ = 0;
203+
const int index_ = 0;
199204
bool keepRunning_ = 0;
200205
IOThread* t_ = nullptr;
201206
int fd_ = 0;

0 commit comments

Comments
 (0)