Skip to content

Commit

Permalink
[swssconfig] Optimize performance of swssconfig (sonic-net#2336)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Junchao-Mellanox authored Jun 24, 2022
1 parent 84e9b07 commit 37349cf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions swssconfig/swssconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ void dump_db_item(KeyOpFieldsValuesTuple &db_item)

bool write_db_data(vector<KeyOpFieldsValuesTuple> &db_items)
{
DBConnector db("APPL_DB", 0, true);
DBConnector db("APPL_DB", 0, false);
RedisPipeline pipeline(&db); // dtor of RedisPipeline will automatically flush data
unordered_map<string, ProducerStateTable> table_map;

for (auto &db_item : db_items)
{
dump_db_item(db_item);
Expand All @@ -55,18 +58,19 @@ bool write_db_data(vector<KeyOpFieldsValuesTuple> &db_items)
}
string table_name = key.substr(0, pos);
string key_name = key.substr(pos + 1);
ProducerStateTable producer(&db, table_name);
auto ret = table_map.emplace(std::piecewise_construct, std::forward_as_tuple(table_name), std::forward_as_tuple(&pipeline, table_name, true));

if (kfvOp(db_item) == SET_COMMAND)
producer.set(key_name, kfvFieldsValues(db_item), SET_COMMAND);
ret.first->second.set(key_name, kfvFieldsValues(db_item), SET_COMMAND);
else if (kfvOp(db_item) == DEL_COMMAND)
producer.del(key_name, DEL_COMMAND);
ret.first->second.del(key_name, DEL_COMMAND);
else
{
SWSS_LOG_ERROR("Invalid operation: %s\n", kfvOp(db_item).c_str());
return false;
}
}

return true;
}

Expand Down

0 comments on commit 37349cf

Please sign in to comment.