From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, den@virtuozzo.com,
Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Subject: Re: [Qemu-devel] [PATCH] monitor: increase amount of data for monitor to read
Date: Tue, 24 Nov 2020 18:44:52 +0300 [thread overview]
Message-ID: <31dd78ba-bd64-2ed6-3c8f-eed4e904d14c@virtuozzo.com> (raw)
In-Reply-To: <20190710163610.GG2682@work-vm>
Hi all!
This patch isn't outdated, it applies on master with a little conflict atomic_mb_read -> qatomic_mb_read
We have new series "[PATCH v2 0/2] Increase amount of data for monitor to read", but I do think that we've started from wrong point. And actually we should start from this old patch.
10.07.2019 19:36, Dr. David Alan Gilbert wrote:
> * Markus Armbruster (armbru@redhat.com) wrote:
>> Did this fall through the cracks?
>>
>> Denis Plotnikov <dplotnikov@virtuozzo.com> writes:
>>
>>> Right now QMP and HMP monitors read 1 byte at a time from the socket, which
>>> is very inefficient. With 100+ VMs on the host this easily reasults in
>>> a lot of unnecessary system calls and CPU usage in the system.
>>
>> Yes, reading one byte at a time is awful. But QMP is control plane; I
>> didn't expect it to impact system performance. How are you using QMP?
>> Just curious, not actually opposed to improving QMP efficiency.
>>
>>> This patch changes the amount of data to read to 4096 bytes, which matches
>>> buffer size on the channel level. Fortunately, monitor protocol is
>>> synchronous right now thus we should not face side effects in reality.
>>>
>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
>>> ---
>>> include/monitor/monitor.h | 2 +-
>>> monitor.c | 2 +-
>>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
>>> index c1b40a9cac..afa1ed34a4 100644
>>> --- a/include/monitor/monitor.h
>>> +++ b/include/monitor/monitor.h
>>> @@ -14,7 +14,7 @@ extern __thread Monitor *cur_mon;
>>> #define MONITOR_USE_CONTROL 0x04
>>> #define MONITOR_USE_PRETTY 0x08
>>>
>>> -#define QMP_REQ_QUEUE_LEN_MAX 8
>>> +#define QMP_REQ_QUEUE_LEN_MAX 4096
>>
>> This looks suspicious. It's a request count, not a byte count. Can you
>> explain what led you to change it this way?
I can explain, because that was my idea:
It's a hack to not overflow the queue. With just the second hunk we overflow it and assertion fails.
So, I decided that if we allow to read up to 4096, we will not add more than 4096 commands simultaneously. And that works..
Still, now I don't think it's enough: who guarantee that we will not read new commands when queue is half-full?
I think, that we just need two limits: QUEUE_SOFT_LEN an QUEUE_HARD_LEN (suggest better names). So, when QUEUE_SOFT_LEN is reached we do suspend the monitor (like when queue is full currently). And in monitor_can_read() we allow to read (QUEUE_HARD_LEN - QUEUE_SOFT_LEN). In this way queue will never overflow the QUEUE_HARD_LEN.
Also, what is the minimum character length of the command? I just decided that better safe than sorry, considering one character as possible full command. What is the smallest command which parser will parse? Is it {} ? Or may be {"execute":""} ? We can use this knowledge, to understand how many commands we should be prepared to accept, when we allow N characters in monitor_can_read(). So, 4096 is probably too much for QMP_REQ_QUEUE_LEN_MAX.
>>
>>>
>>> bool monitor_cur_is_qmp(void);
>>>
>>> diff --git a/monitor.c b/monitor.c
>>> index 4807bbe811..a08e020b61 100644
>>> --- a/monitor.c
>>> +++ b/monitor.c
>>> @@ -4097,7 +4097,7 @@ static int monitor_can_read(void *opaque)
>>> {
>>> Monitor *mon = opaque;
>>>
>>> - return !atomic_mb_read(&mon->suspend_cnt);
>>> + return !atomic_mb_read(&mon->suspend_cnt) ? 4096 : 0;
>>> }
>>>
>>> /*
>>
>> The ramifications are not obvious to me. I think I need to (re-)examine
>> how QMP reads input, with special consideration to its OOB feature.
>
> Yeh that was the bit that worried me; I also wondered what happens with
> monitor_suspend and things like fd passing; enough to make it
> non-obvious to me.
>
OK, I don't have answers..
Markus, David, could you please help? Or, what to do? We of course don't have enough expertise to prove that patch will not break any feature in the whole monitor subsystem.
I can say that it just works, and we live with it for years (and our customers too), and tests pass. Still, I don't think that we use OOB feature. I remember some problems with it, when RHEL version which we were based on included some OOB feature patches, but not some appropriate fixes.. But it was long ago.
If nobody can say that patch is wrong, maybe, we can just apply it? We'll have the whole release cycle to catch any bugs and revert the commit at any time. In this way we only have a question about QMP_REQ_QUEUE_LEN_MAX, which is quite simple.
--
Best regards,
Vladimir
next prev parent reply other threads:[~2020-11-24 15:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-10 10:59 [Qemu-devel] [PATCH] monitor: increase amount of data for monitor to read Denis Plotnikov
2019-07-03 6:36 ` Markus Armbruster
2019-07-03 7:18 ` Denis Lunev
2019-07-10 16:36 ` Dr. David Alan Gilbert
2020-11-24 15:44 ` Vladimir Sementsov-Ogievskiy [this message]
2021-03-02 17:06 ` Vladimir Sementsov-Ogievskiy
2021-03-05 14:10 ` Markus Armbruster
2021-03-05 14:47 ` Vladimir Sementsov-Ogievskiy
2021-03-05 16:13 ` Markus Armbruster
2021-03-05 16:20 ` Vladimir Sementsov-Ogievskiy
2021-03-06 7:15 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31dd78ba-bd64-2ed6-3c8f-eed4e904d14c@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=andrey.shinkevich@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@virtuozzo.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).