Skip to content

Commit 37349cf

Browse files
[swssconfig] Optimize performance of swssconfig (#2336)
- What I did Optimize swssconfig: 1. Use unix socket 2. Cache producer table to avoid create it for same table name - Why I did it We found that generating large scale static routes via swssconfig is very slow. - How I verified it After the optimization, generating 100K routes via swssconfig take 2 seconds, however, before the optimization it takes > 60 seconds.
1 parent 84e9b07 commit 37349cf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

swssconfig/swssconfig.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ void dump_db_item(KeyOpFieldsValuesTuple &db_item)
4141

4242
bool write_db_data(vector<KeyOpFieldsValuesTuple> &db_items)
4343
{
44-
DBConnector db("APPL_DB", 0, true);
44+
DBConnector db("APPL_DB", 0, false);
45+
RedisPipeline pipeline(&db); // dtor of RedisPipeline will automatically flush data
46+
unordered_map<string, ProducerStateTable> table_map;
47+
4548
for (auto &db_item : db_items)
4649
{
4750
dump_db_item(db_item);
@@ -55,18 +58,19 @@ bool write_db_data(vector<KeyOpFieldsValuesTuple> &db_items)
5558
}
5659
string table_name = key.substr(0, pos);
5760
string key_name = key.substr(pos + 1);
58-
ProducerStateTable producer(&db, table_name);
61+
auto ret = table_map.emplace(std::piecewise_construct, std::forward_as_tuple(table_name), std::forward_as_tuple(&pipeline, table_name, true));
5962

6063
if (kfvOp(db_item) == SET_COMMAND)
61-
producer.set(key_name, kfvFieldsValues(db_item), SET_COMMAND);
64+
ret.first->second.set(key_name, kfvFieldsValues(db_item), SET_COMMAND);
6265
else if (kfvOp(db_item) == DEL_COMMAND)
63-
producer.del(key_name, DEL_COMMAND);
66+
ret.first->second.del(key_name, DEL_COMMAND);
6467
else
6568
{
6669
SWSS_LOG_ERROR("Invalid operation: %s\n", kfvOp(db_item).c_str());
6770
return false;
6871
}
6972
}
73+
7074
return true;
7175
}
7276

0 commit comments

Comments
 (0)