2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-28 12:58:00 +00:00

14 Commits

Author SHA1 Message Date
Ilya Maximets
0b21e23431 json: Fix deep copy of objects and arrays.
When reference counting for json objects was introduced the
old json_clone() function became json_deep_clone(), but it
still calls shallow json_clone() while cloning objects and
arrays not really producing a deep copy.

Fixing that by making other functions to perform a deep copy
as well.  There are no users for this functionality inside
OVS right now, but OVS exports this functionality externally.

'ovstest test-json' extended to test both versions of a clone
on provided inputs.

Fixes: 9854d473adea ("json: Use reference counting in JSON objects")
Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-10-11 21:10:46 +02:00
Ilya Maximets
9632f5551f tests: Add de-serialization check to the json string benchmark.
Since we're testing serialization, it also makes sense to test
the opposite operation.  Should be useful in the future for
exploring possible optimizations.

CMD: $ ./tests/ovstest json-string-benchmark

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2022-01-31 21:15:25 +01:00
Ilya Maximets
748010ff30 json: Optimize string serialization.
Current string serialization code puts all characters one by one.
This is slow because dynamic string needs to perform length checks
on every ds_put_char() and it's also doesn't allow compiler to use
better memory copy operations, i.e. doesn't allow copying few bytes
at once.

Special symbols are rare in a typical database.  Quotes are frequent,
but not too frequent.  In databases created by ovn-kubernetes, for
example, usually there are at least 10 to 50 chars between quotes.
So, it's better to count characters that doesn't require escaping
and use fast data copy for the whole sequential block.

Testing with a synthetic benchmark (included) on my laptop shows
following performance improvement:

   Size      Q  S       Before       After       Diff
 -----------------------------------------------------
 100000      0  0 :    0.227 ms     0.142 ms   -37.4 %
 100000      2  1 :    0.277 ms     0.186 ms   -32.8 %
 100000      10 1 :    0.361 ms     0.309 ms   -14.4 %
 10000000    0  0 :   22.720 ms    12.160 ms   -46.4 %
 10000000    2  1 :   27.470 ms    19.300 ms   -29.7 %
 10000000    10 1 :   37.950 ms    31.250 ms   -17.6 %
 100000000   0  0 :  239.600 ms   126.700 ms   -47.1 %
 100000000   2  1 :  292.400 ms   188.600 ms   -35.4 %
 100000000   10 1 :  387.700 ms   321.200 ms   -17.1 %

Here Q - probability (%) for a character to be a '\"' and
S - probability (%) to be a special character ( < 32).

Testing with a closer to real world scenario shows overall decrease
of the time needed for database compaction by ~5-10 %.  And this
change also decreases CPU consumption in general, because string
serialization is used in many different places including ovsdb
monitors and raft.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Numan Siddique <numans@ovn.org>
Acked-by: Dumitru Ceara <dceara@redhat.com>
2021-08-31 19:04:08 +02:00
Ben Pfaff
fa37affad3 Embrace anonymous unions.
Several OVS structs contain embedded named unions, like this:

struct {
    ...
    union {
        ...
    } u;
};

C11 standardized a feature that many compilers already implemented
anyway, where an embedded union may be unnamed, like this:

struct {
    ...
    union {
        ...
    };
};

This is more convenient because it allows the programmer to omit "u."
in many places.  OVS already used this feature in several places.  This
commit embraces it in several others.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
Tested-by: Alin Gabriel Serdean <aserdean@ovn.org>
Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
2018-05-25 13:36:05 -07:00
Terry Wilson
ee89ea7b47 json: Move from lib to include/openvswitch.
To easily allow both in- and out-of-tree building of the Python
wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to
include/openvswitch. This also requires moving lib/{hmap,shash}.h.

Both hmap.h and shash.h were #include-ing "util.h" even though the
headers themselves did not use anything from there, but rather from
include/openvswitch/util.h. Fixing that required including util.h
in several C files mostly due to OVS_NOT_REACHED and things like
xmalloc.

Signed-off-by: Terry Wilson <twilson@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-07-22 17:09:17 -07:00
Jarno Rajahalme
3f636c7e22 ovs_assert, tests: Support NDEBUG.
./configure accepts --enable-ndebug option.  Make ovs_assert() honor
it, and make sure all test programs disable it.

The order of include files in test programs is also made uniform:

1. #include <config.h>
2. #undef NDEBUG
3. Include file of the test subject (to make sure it itself has
   sufficient include directives).
4. System includes in alphapetical order.
5. OVS includes in aplhapetical order.

Suggested-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-10-30 09:14:46 -07:00
Andy Zhou
eadd16449c unit-test: Link 29 test programs into ovstest
Improve link speed by linking 29 test programs into ovstest.

On my machine, running the following command against a fully
built tree:

  $ touch lib/random.c; time make

Improve the overall build time from 7 seconds to 3.5 seconds.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-04-03 11:17:17 -07:00
Ben Pfaff
a11fdef12e Revert "json: New function json_serialized_length()."
This reverts commit 1600fa6853872e16130366351a2c14f6fa8b547c.

Connections that queue up too much data, because they are monitoring a
table that is changing quickly and failing to keep up with the updates,
cause problems with buffer management.  Since commit 60533a405b2e
(jsonrpc-server: Disconnect connections that queue too much data.),
ovsdb-server has dealt with them by disconnecting the connection and
letting them start up again with a fresh copy of the database.  However,
this is not ideal because of situations where disconnection happens
repeatedly.  For example:

     - A manager toggles a column back and forth between two or more values
       quickly (in which case the data transmitted over the monitoring
       connections always increases quickly, without bound).

     - A manager repeatedly extends the contents of some column in some row
       (in which case the data transmitted over the monitoring connection
       grows with O(n**2) in the length of the string).

A better way to deal with this problem is to combine updates when they are
sent to the monitoring connection, if that connection is not keeping up.
In both the above cases, this reduces the data that must be sent to a
manageable amount.  An upcoming patch implements this new way.  This commit
reverts part of the previous solution that disconnects backlogged
connections, since it is no longer useful.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2014-04-03 07:53:54 -07:00
Ben Pfaff
1600fa6853 json: New function json_serialized_length().
This will be used for the first time in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-01 13:16:59 -07:00
Raju Subramanian
e0edde6fee Global replace of Nicira Networks.
Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc.

Feature #10593
Signed-off-by: Raju Subramanian <rsubramanian@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-02 17:08:02 -07:00
Ben Pfaff
93ff0290fd tests: Fix memory leaks in test programs.
This makes it easier to see memory leaks in the code under test.

Found with valgrind.
2010-02-02 15:21:10 -08:00
Ben Pfaff
5562d6f55e test-json: Avoid use of /dev/stdin to fix builds in limited chroots.
The chroots in which we often build Open vSwitch don't have /proc and
thus cannot support /dev/stdin, because on Linux that is a symlink to
/proc/self/fd/0.  So avoid using /dev/stdin in the testsuite.
2009-12-17 15:50:01 -08:00
Ben Pfaff
f212909325 Implement JSON-RPC protocol. 2009-11-04 15:24:40 -08:00
Ben Pfaff
f38b84ea2b Implement JSON parsing and serialization.
This will be used by the upcoming Open vSwitch configuration database.
2009-11-04 15:24:40 -08:00