MXS-2259: Limit size of client reads

Given the assumption that queries are rarely 16MB long and that
realistically the only time that happens is during a large dump of data,
we can limit the size of a single read to at most one MariaDB/MySQL packet
at a time. This change allows the network throttling to engage a lot
sooner and reduces the maximum overshoot of throtting to 16MB.
This commit is contained in:
Markus Mäkelä
2019-04-05 11:04:04 +03:00
parent aad29404c6
commit 05515cca16
3 changed files with 14 additions and 3 deletions

View File

@ -489,7 +489,10 @@ int gw_read_client_event(DCB* dcb)
{
max_bytes = 36;
}
return_code = dcb_read(dcb, &read_buffer, max_bytes);
const uint32_t max_single_read = GW_MYSQL_MAX_PACKET_LEN + MYSQL_HEADER_LEN;
return_code = dcb_read(dcb, &read_buffer, max_bytes > 0 ? max_bytes : max_single_read);
if (return_code < 0)
{
dcb_close(dcb);
@ -499,6 +502,13 @@ int gw_read_client_event(DCB* dcb)
return return_code;
}
if (nbytes_read == max_single_read && dcb_bytes_readable(dcb) > 0)
{
// We read a maximally long packet, route it first. This is done in case there's a lot more data
// waiting and we have to start throttling the reads.
poll_fake_read_event(dcb);
}
return_code = 0;
switch (protocol->protocol_auth_state)