Skip to content

Commit 34a492f

Browse files
committed
UPD | stopping mechanism
1 parent 08bed04 commit 34a492f

17 files changed

Lines changed: 304 additions & 42 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake-build-debug
22
cmake-build-release
3+
cmake-build-exe
34
examples/CMakeFiles
45
examples/CMakeCache.txt
56
examples/cmake_install.cmake

include/http/ManapiHttpConfig.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ namespace manapi::net::http {
100100
*/
101101
static manapi::error::status_or<http::versions::http> parse_http_version (std::string_view version) MANAPIHTTP_NOEXCEPT;
102102

103-
// settings
104-
int max_working_streams;
105-
106103
/**
107104
* For Http/2 and QUIC
108105
* Max concurrent streams by the connection
@@ -259,6 +256,14 @@ namespace manapi::net::http {
259256
* Sets the minimum limit rate every 'speed_check_delay' seconds
260257
*/
261258
ssize_t speed_check_bytes;
259+
/**
260+
* Sets the speed check delay interval
261+
*/
262+
ssize_t speed_stream_check_delay;
263+
/**
264+
* Sets the minimum limit rate every 'speed_check_delay' seconds
265+
*/
266+
ssize_t speed_stream_check_bytes;
262267

263268
/**
264269
* Sets the maximum limit rate every second

include/worker/ManapiBaseUtils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ auto const prev = std::exchange(n__->flags, ((n__->flags >> 2) << 2) | (flags &
88
if (n__->flags & CONN_EVENT_LOCKED) return prev; \
99
n__->flags |= CONN_EVENT_LOCKED; auto status = n__->flags; \
1010
while (true)
11+
#define MANAPIHTTP_WORKER_EVENT_LOOP_STREAM(n__) n__->speed_min_delay = static_cast<int>(this->config()->speed_stream_check_delay); \
12+
auto const prev = std::exchange(n__->flags, ((n__->flags >> 2) << 2) | (flags & CONN_MASK_UPDATE)); \
13+
if (n__->flags & CONN_EVENT_LOCKED) return prev; \
14+
n__->flags |= CONN_EVENT_LOCKED; auto status = n__->flags; \
15+
while (true)
1116
#define MANAPIHTTP_WORKER_EVENT_BREAK(n__) if (status != n__->flags) { status = n__->flags; continue; }\
1217
assert (n__->flags & CONN_EVENT_LOCKED); n__->flags ^= CONN_EVENT_LOCKED; break;
1318

@@ -89,6 +94,8 @@ namespace manapi::net::worker {
8994

9095
void feed_event (worker::base *w, const shared_conn &conn, int flags, const char *buff, ssize_t size, ibuffpool_t *p) MANAPIHTTP_NOEXCEPT;
9196

97+
void update_limit_rate_connection (const shared_conn &sconn, connection_prepared_base_t *data, worker::base *w, http::config *config, ssize_t speed_check_delay, ssize_t speed_check_bytes, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT;
98+
9299
void update_limit_rate_connection (const shared_conn &sconn, connection_prepared_base_t *data, worker::base *w, http::config *config, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT;
93100

94101
void update_limit_rate_connection (const shared_conn &sconn, worker::base *w, http::config *config, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT;

src/http/ManapiHttp2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ int manapi::net::http::http_v2_work(http_v2_t *ctx, http::config *config, const
13701370
sdata = s->second->as<http_v2_stream_t>();
13711371
sdata->req = std::move(req_tmp);
13721372
sdata->top = std::move(top_tmp);
1373-
sdata->speed_min_delay = static_cast<int>(config->speed_check_delay);
1373+
sdata->speed_min_delay = static_cast<int>(config->speed_stream_check_delay);
13741374

13751375
sdata->req->divided = -1;
13761376
sdata->req->http = http::versions::http::HTTP_v2;

src/http/ManapiHttpConfig.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ enum http_version_bits {
2323
manapi::net::http::config::config(const json &config) {
2424
this->http_versions = 0;
2525
this->server_len = 0;
26-
this->max_working_streams = get_config_param<ssize_t> (config, "max_working_streams", 6);
2726
this->window_stream_size = get_config_param<ssize_t> (config, "window_stream_size", 2000000);
2827
this->window_connection_size = get_config_param<ssize_t> (config, "window_connection_size", 4000000);
2928
this->max_concurrent_streams = get_config_param<ssize_t> (config, "max_concurrent_streams", -1);
@@ -46,6 +45,8 @@ manapi::net::http::config::config(const json &config) {
4645
this->tcp_no_delay = get_config_param<bool>(config, "tcp_no_delay", false);
4746
this->speed_check_delay = get_config_param<ssize_t>(config, "speed_check_delay", 5);
4847
this->speed_check_bytes = get_config_param<ssize_t>(config, "speed_check_bytes", 1048576);
48+
this->speed_stream_check_delay = get_config_param<ssize_t>(config, "speed_stream_check_delay", 5);
49+
this->speed_stream_check_bytes = get_config_param<ssize_t>(config, "speed_stream_check_bytes", 1048576);
4950
this->simultaneous_accepts = get_config_param<bool>(config, "simultaneous_accepts", false);
5051
this->max_headers_size = get_config_param<ssize_t>(config, "max_headers_size", 16384);
5152
this->max_header_key_size = get_config_param<ssize_t>(config, "max_header_key_size", 64);

src/http/ManapiNgHttp2Interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static int ng_wrk_http2_on_begin_headers_callback(nghttp2_session *session, cons
530530
auto const id = frame->hd.stream_id;
531531

532532
auto tp = std::make_unique<http_v2_stream_t>();
533-
tp->speed_min_delay = static_cast<decltype(tp->speed_min_delay)>(sess->gctx->worker->config()->speed_check_delay);
533+
tp->speed_min_delay = static_cast<decltype(tp->speed_min_delay)>(sess->gctx->worker->config()->speed_stream_check_delay);
534534
tp->id = id;
535535
tp->top = std::make_unique<manapi::net::worker::connection_io>();
536536
tp->req = std::make_unique<manapi::net::http::request_data_t>();

src/http/ManapiNgHttp3Interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,16 +1323,16 @@ static int ng_wrk_http3_rst (const manapi::net::worker::shared_conn &conn, int c
13231323
}
13241324

13251325
if (s->s)
1326-
s->ctx->gctx->worker->close_connection(s->s, manapi::net::worker::CLOSE_CONN_ERR);
1326+
s->ctx->gctx->worker->close_connection(s->s, manapi::net::worker::CLOSE_CONN_SHUTDOWN);
13271327

13281328
ng_wrk_http3_flush_close(s->ctx);
13291329
}
13301330
else {
13311331
if (s->s)
1332-
s->ctx->gctx->worker->close_connection(s->s, manapi::net::worker::CLOSE_CONN_ERR);
1332+
s->ctx->gctx->worker->close_connection(s->s, manapi::net::worker::CLOSE_CONN_SHUTDOWN);
13331333

13341334
if (!s->ctx->active_connections)
1335-
s->ctx->gctx->worker->close_connection(s->ctx->conn, manapi::net::worker::CLOSE_CONN_ERR);
1335+
s->ctx->gctx->worker->close_connection(s->ctx->conn, manapi::net::worker::CLOSE_CONN_SHUTDOWN);
13361336
}
13371337

13381338
return manapi::ERR_OK;

src/worker/ManapiBaseUtils.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void manapi::net::worker::prepared::feed_event(worker::base *w, const shared_con
175175
return feed_event(w, conn, data, flags, buff, size, p);
176176
}
177177

178-
void manapi::net::worker::prepared::update_limit_rate_connection(const shared_conn &sconn, connection_prepared_base_t *data, worker::base *w, http::config *config, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT {
178+
void manapi::net::worker::prepared::update_limit_rate_connection(const shared_conn &sconn, connection_prepared_base_t *data, worker::base *w, http::config *config, ssize_t speed_check_delay, ssize_t speed_check_bytes, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT {
179179
if (data->transfered >= config->speed_limit_rate
180180
&& data->ev_callback) {
181181
data->transfered = 0;
@@ -186,19 +186,19 @@ void manapi::net::worker::prepared::update_limit_rate_connection(const shared_co
186186
return;
187187
}
188188
}
189-
}
189+
}
190190
else {
191191
data->transfered_k += data->transfered;
192192

193193
if (--data->speed_min_delay <= 0) {
194194
if (data->flags & (base::CONN_IO_WAITING)
195-
&& (data->transfered_k < config->speed_check_bytes)) {
195+
&& (data->transfered_k < speed_check_bytes)) {
196196
w->close_connection(sconn, CLOSE_CONN_ERR);
197197
return;
198-
}
198+
}
199199

200200
data->transfered_k = 0;
201-
data->speed_min_delay = static_cast<int>(config->speed_check_delay);
201+
data->speed_min_delay = static_cast<int>(speed_check_delay);
202202
}
203203

204204
data->transfered = 0;
@@ -208,6 +208,10 @@ void manapi::net::worker::prepared::update_limit_rate_connection(const shared_co
208208
global->update_limit_rate(sconn, global, w);
209209
}
210210

211+
void manapi::net::worker::prepared::update_limit_rate_connection(const shared_conn &sconn, connection_prepared_base_t *data, worker::base *w, http::config *config, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT {
212+
return update_limit_rate_connection(sconn, data, w, config, config->speed_check_delay, config->speed_check_delay, global);
213+
}
214+
211215
void manapi::net::worker::prepared::update_limit_rate_connection(const shared_conn &sconn, worker::base *w, http::config *config, wrk_interface_global_t *global) MANAPIHTTP_NOEXCEPT {
212216
update_limit_rate_connection(sconn, sconn->as<connection_prepared_base_t>(), w, config, global);
213217
}

src/worker/ManapiHttp2Worker.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void manapi::net::worker::http_v2::close_connection(shared_conn conn, int flags)
6565
return;
6666

6767
/* got something wrong */
68-
this->callbacks->http_v2_rst_stream(conn, HTTP2_ERROR_REFUSED_STREAM);
68+
this->callbacks->http_v2_rst_stream(conn, HTTP2_ERROR_NO_ERROR);
6969
}
7070

7171
int manapi::net::worker::http_v2::event_flags(const shared_conn & conn) MANAPIHTTP_NOEXCEPT {
@@ -75,7 +75,7 @@ int manapi::net::worker::http_v2::event_flags(const shared_conn & conn) MANAPIHT
7575
int manapi::net::worker::http_v2::event_flags(const shared_conn & conn, int flags) MANAPIHTTP_NOEXCEPT {
7676
auto const data = conn->as<http_v2_stream_base_t>();
7777

78-
MANAPIHTTP_WORKER_EVENT_LOOP(data) {
78+
MANAPIHTTP_WORKER_EVENT_LOOP_STREAM(data) {
7979
if (data->ev_callback) {
8080
if (data->flags & CONN_CLOSED) {
8181
if (http_v2::call_user_callback(&data->ev_callback, conn, CONN_CLOSED, nullptr, 0, nullptr))
@@ -135,7 +135,8 @@ ssize_t manapi::net::worker::http_v2::sync_write_ex(const shared_conn &conn, ev:
135135
}
136136

137137
void manapi::net::worker::http_v2::update_limit_rate_stream(const shared_conn &conn) MANAPIHTTP_NOEXCEPT {
138-
return prepared::update_limit_rate_connection(conn, this, this->config(), this->wrk_global());
138+
auto const c = this->config();
139+
return prepared::update_limit_rate_connection(conn, conn->as<connection_prepared_base_t>(), this, c, c->speed_stream_check_delay, c->speed_stream_check_bytes, this->wrk_global());
139140
}
140141

141142
std::size_t manapi::net::worker::http_v2::recv_count(const shared_conn &conn) const MANAPIHTTP_NOEXCEPT {

src/worker/ManapiHttp3Worker.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void manapi::net::worker::http_v3::close_connection(shared_conn conn, int flags)
6767
return;
6868

6969
/* got something wrong */
70-
this->callbacks->http_v3_rst_stream(conn, HTTP3_ERROR_REQUEST_CANCELLED);
70+
this->callbacks->http_v3_rst_stream(conn, HTTP3_ERROR_NO_ERROR);
7171
}
7272

7373
int manapi::net::worker::http_v3::event_flags(const shared_conn &conn) MANAPIHTTP_NOEXCEPT {
@@ -77,7 +77,7 @@ int manapi::net::worker::http_v3::event_flags(const shared_conn &conn) MANAPIHTT
7777
int manapi::net::worker::http_v3::event_flags(const shared_conn &conn, int flags) MANAPIHTTP_NOEXCEPT {
7878
auto const data = MANAPI_AS_STREAM(conn->wrk.data);
7979

80-
MANAPIHTTP_WORKER_EVENT_LOOP(data) {
80+
MANAPIHTTP_WORKER_EVENT_LOOP_STREAM(data) {
8181
if (data->ev_callback) {
8282
if (data->flags & CONN_CLOSED) {
8383
if (http_v3::call_user_callback(&data->ev_callback, conn, CONN_CLOSED, nullptr, 0, nullptr))
@@ -137,7 +137,8 @@ ssize_t manapi::net::worker::http_v3::sync_write_ex(const shared_conn &conn, ev:
137137
}
138138

139139
void manapi::net::worker::http_v3::update_limit_rate_stream(const shared_conn &conn) MANAPIHTTP_NOEXCEPT {
140-
prepared::update_limit_rate_connection(conn, MANAPI_AS_STREAM(conn->wrk.data), this, this->config(), this->wrk_global());
140+
auto const c = this->config();
141+
return prepared::update_limit_rate_connection(conn, MANAPI_AS_STREAM(conn->wrk.data), this, c, c->speed_stream_check_delay, c->speed_stream_check_bytes, this->wrk_global());
141142
}
142143

143144
std::size_t manapi::net::worker::http_v3::recv_count(const shared_conn &conn) const MANAPIHTTP_NOEXCEPT {

0 commit comments

Comments
 (0)