On 7/1/21 8:19 PM, Terry Wilson wrote:
> When using eventlet monkey_patch()'d code, greenthreads can be
> blocked on connection for several seconds while the database
> contents are parsed. Eventlet recommends adding a sleep(0) call
> to cooperatively yield in cpu-bound code. asyncio code has
> asyncio.sleep(0). This patch adds an API  method that defaults to
> doing nothing, but can be overridden to yield as needed.
> 
> Signed-off-by: Terry Wilson <twil...@redhat.com>
> ---
>  python/ovs/db/idl.py | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
> index 889cf3431..751feb47f 100644
> --- a/python/ovs/db/idl.py
> +++ b/python/ovs/db/idl.py
> @@ -479,6 +479,15 @@ class Idl(object):
>          :type updates:  Row
>          """
>  
> +    def cooperative_yield(self):
> +        """Hook for cooperatively yielding to eventlet/gevent/asyncio/etc.
> +
> +        When a block of code is going to spend a lot of time cpu-bound 
> without
> +        doing any I/O, it can cause greenthread/coroutine libraries to block.
> +        This call should be added to code where this can happen, but defaults
> +        to doing nothing to avoid overhead where it is not needed.
> +        """
> +
>      def __send_cond_change(self, table, cond):
>          monitor_cond_change = {table.name: [{"where": cond}]}
>          old_uuid = str(self.uuid)
> @@ -644,6 +653,8 @@ class Idl(object):
>                                        'is not an object'
>                                        % (table_name, uuid_string))
>  
> +                self.cooperative_yield()
> +
>                  if version == OVSDB_UPDATE2:
>                      changes = self.__process_update2(table, uuid, row_update)
>                      if changes:
> 

Thanks, Terry!  I added a NEWS entry for this and applied to master,
so it will be part of 2.16 release.

Best regards, Ilya Maximets.
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to