Skip to content

Commit

Permalink
python: avoid useless JSON conversion to enhance performance
Browse files Browse the repository at this point in the history
This patch removes a useless conversion to/from JSON in the
processing of any 'modify' operations inside the process_update2
method in Python IDL implementation.

Previous code will make resources creation take longer as the number
of elements in the row grows because of that JSON conversion. This
patch eliminates it and now the time remains consant regardless
of the database contents improving performance and scaling.

Reported-by: Daniel Alvarez <dalvarez@redhat.com>
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2018-February/046263.html
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
Acked-by: Terry Wilson <twilson@redhat.com>
Tested-By: Terry Wilson <twilson@redhat.com>
Acked-by: Han Zhou <hzhou8@ebay.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
danalsan authored and blp committed Jun 13, 2018
1 parent afd2ebe commit 9d52a31
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions python/ovs/db/idl.py
Expand Up @@ -533,10 +533,8 @@ def __process_update2(self, table, uuid, row_update):
if not row:
raise error.Error('Modify non-existing row')

old_row_diff_json = self.__apply_diff(table, row,
row_update['modify'])
self.notify(ROW_UPDATE, row,
Row.from_json(self, table, uuid, old_row_diff_json))
old_row = self.__apply_diff(table, row, row_update['modify'])
self.notify(ROW_UPDATE, row, Row(self, table, uuid, old_row))
changed = True
else:
raise error.Error('<row-update> unknown operation',
Expand Down Expand Up @@ -605,7 +603,7 @@ def __add_default(self, table, row_update):
row_update[column.name] = self.__column_name(column)

def __apply_diff(self, table, row, row_diff):
old_row_diff_json = {}
old_row = {}
for column_name, datum_diff_json in six.iteritems(row_diff):
column = table.columns.get(column_name)
if not column:
Expand All @@ -622,12 +620,12 @@ def __apply_diff(self, table, row, row_diff):
% (column_name, table.name, e))
continue

old_row_diff_json[column_name] = row._data[column_name].to_json()
old_row[column_name] = row._data[column_name].copy()
datum = row._data[column_name].diff(datum_diff)
if datum != row._data[column_name]:
row._data[column_name] = datum

return old_row_diff_json
return old_row

def __row_update(self, table, row, row_json):
changed = False
Expand Down

0 comments on commit 9d52a31

Please sign in to comment.