From 37349cfc85d3c6f0b16f4bc086179af632415cff Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Sat, 25 Jun 2022 01:10:39 +0800 Subject: [PATCH] [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. --- swssconfig/swssconfig.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/swssconfig/swssconfig.cpp b/swssconfig/swssconfig.cpp index a41ef0ecdd77..e61d038381d7 100644 --- a/swssconfig/swssconfig.cpp +++ b/swssconfig/swssconfig.cpp @@ -41,7 +41,10 @@ void dump_db_item(KeyOpFieldsValuesTuple &db_item) bool write_db_data(vector &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 table_map; + for (auto &db_item : db_items) { dump_db_item(db_item); @@ -55,18 +58,19 @@ bool write_db_data(vector &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; }