Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for small bandwidth-downstream #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tcpkali_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
struct connection {
tk_io watcher;
tk_timer timer;
double timer_deadline;
off_t write_offset;
struct transport_data_spec data;
non_atomic_traffic_stats traffic_ongoing; /* Connection-local numbers */
Expand Down
27 changes: 22 additions & 5 deletions src/tcpkali_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,7 @@ conn_timer_cb(TK_P_ tk_timer *w, int UNUSED revents) {
struct connection *conn =
(struct connection *)((char *)w - offsetof(struct connection, timer));

conn->timer_deadline = 0;
switch(conn->conn_state) {
case CSTATE_CONNECTED:
switch(conn->conn_type) {
Expand Down Expand Up @@ -1568,8 +1569,6 @@ static void
connection_timer_refresh(TK_P_ struct connection *conn, double delay) {
struct loop_arguments *largs = tk_userdata(TK_A);

tk_timer_stop(TK_A, &conn->timer);

switch(conn->conn_state) {
case CSTATE_CONNECTED:
/* Use the supplied delay */
Expand All @@ -1579,7 +1578,21 @@ connection_timer_refresh(TK_P_ struct connection *conn, double delay) {
break;
}

double now = tk_now(TK_A);

/*
* Do nothing if we already have a timer which
* is going to be fired sooner than the new one
*/
if(conn->timer_deadline > 0 && conn->timer_deadline < now + delay) {
return;
}

tk_timer_stop(TK_A, &conn->timer);
conn->timer_deadline = 0;

if(delay > 0.0) {
conn->timer_deadline = now + delay;
#ifdef USE_LIBUV
uv_timer_init(TK_A_ & conn->timer);
uint64_t uint_delay = 1000 * delay;
Expand All @@ -1602,6 +1615,7 @@ common_connection_init(TK_P_ struct connection *conn, enum conn_type conn_type,

conn->conn_type = conn_type;
conn->conn_state = conn_state;
conn->timer_deadline = 0;

maybe_enable_dump(largs, conn_type, sockfd);

Expand Down Expand Up @@ -1936,10 +1950,11 @@ static enum lb_return_value {
* So if the reading allowance is too small, make it
* large enough still to batch reads.
*/
if(allowed_to_move > 1460)
if(limit.bytes_per_second < allowed_to_move) {
*suggested_move_size = allowed_to_move;
else
*suggested_move_size = 1460;
} else if(limit.bytes_per_second < *suggested_move_size) {
*suggested_move_size = limit.bytes_per_second;
}
return LB_PROCEED;
}
} else {
Expand All @@ -1960,6 +1975,7 @@ static enum lb_return_value {
}

if(delay < 0.001) delay = 0.001;
if(delay > 1) delay = 1;

connection_timer_refresh(TK_A_ conn, delay);

Expand Down Expand Up @@ -2504,6 +2520,7 @@ connection_cb(TK_P_ tk_io *w, int revents) {
* If there's nothing to write, we remove the write interest.
*/
tk_timer_stop(TK_A, &conn->timer);
conn->timer_deadline = 0;
if((conn->data.total_size == 0) && !(conn->conn_blocked & CBLOCKED_ON_WRITE)) {
conn->conn_wish &= ~CW_WRITE_INTEREST; /* Remove write interest */
update_io_interest(TK_A_ conn);
Expand Down