-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sonic-db-cli high CPU usage on SONiC startup #10218
Labels
Comments
Thanks for raising the issue and detailed analysis! Could you attach "the PoC code"? Are you able to submit a PR (may in draft) and we can keep discussing on PR. |
The code that I used for test: #include <swss/sonicv2connector.h>
#include <getopt.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <vector>
static std::string nameSpace;
static std::string dbOrOperation;
static std::vector<std::string> commands;
static int useUnixSocket;
static int helpRequested;
void printUsage()
{
std::cerr << "usage: sonic-db-cli [-h] [-s] [-n NAMESPACE] db_or_op [cmd ...]" << std::endl;
}
void parseCliArguments(int argc, char** argv)
{
for (int index = 1; index < argc; index++)
{
std::string opt{argv[index]};
if (opt == "-h" || opt == "--help")
{
helpRequested = true;
}
else if (opt == "-n" || opt == "--namespace")
{
index++;
if (index == argc)
{
throw std::invalid_argument("namespace option requires argument");
}
nameSpace = argv[index];
}
else if (opt == "-s" || opt == "--unixsocket")
{
useUnixSocket = true;
}
else
{
if (dbOrOperation.empty())
{
dbOrOperation = argv[index];
}
else
{
commands.emplace_back(argv[index]);
}
}
}
}
void printRedisReply(redisReply* reply)
{
switch(reply->type)
{
case REDIS_REPLY_INTEGER:
std::cout << reply->integer;
break;
case REDIS_REPLY_STRING:
case REDIS_REPLY_ERROR:
case REDIS_REPLY_STATUS:
case REDIS_REPLY_NIL:
std::cout << std::string(reply->str, reply->len);
break;
case REDIS_REPLY_ARRAY:
for (size_t i = 0; i < reply->elements; i++)
{
printRedisReply(reply->element[i]);
}
break;
default:
std::cerr << reply->type << std::endl;
throw std::runtime_error("Unexpected reply type");
}
std::cout << std::endl;
}
void executeCommands(const std::string& dbname, std::vector<std::string>& commands)
{
swss::SonicV2Connector_Native conn(useUnixSocket, nameSpace.c_str());
conn.connect(dbname);
auto& client = conn.get_redis_client(dbname);
swss::RedisCommand r;
size_t argc = commands.size();
const char** argv = new const char*[argc];
size_t* argvc = new size_t[argc];
for (size_t i = 0; i < argc; i++)
{
argv[i] = strdup(commands[i].c_str());
argvc[i] = commands[i].size();
}
swss::RedisCommand c;
c.formatArgv(argc, argv, argvc);
swss::RedisReply reply(&client, c);
auto redisReply = reply.getContext();
printRedisReply(redisReply);
}
void handleSingleOperation(const std::string& ns, const std::string& operation)
{
swss::SonicV2Connector_Native conn(useUnixSocket, ns.c_str());
conn.connect("APPL_DB");
auto& client = conn.get_redis_client("APPL_DB");
swss::RedisReply reply(&client, operation);
auto redisReply = reply.getContext();
printRedisReply(redisReply);
}
void handleOperation()
{
if (dbOrOperation == "PING" || dbOrOperation == "SAVE" || dbOrOperation == "FLUSHALL")
{
handleSingleOperation(nameSpace, dbOrOperation);
}
else if (!commands.empty())
{
executeCommands(dbOrOperation, commands);
}
else
{
throw std::runtime_error("Invalid operation");
}
}
int main(int argc, char** argv)
{
try
{
parseCliArguments(argc, argv);
handleOperation();
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
return -1;
}
return 0;
} |
ETA of this issue will be 2022/05/31 |
liuh-80
added a commit
to sonic-net/sonic-swss-common
that referenced
this issue
May 26, 2022
) #### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++. #### How to verify it Add c++ unit test to cover all code. Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Re-write sonic-cli with c++ for sonic startup performance issue
liuh-80
added a commit
that referenced
this issue
Jun 1, 2022
) #### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Modify swss-common rules and slave.mk to install c++ version sonic-db-cli. #### How to verify it Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Build and install c++ version sonic-db-cli from swss-common. #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. --> #### A picture of a cute animal (not mandatory but encouraged)
liuh-80
added a commit
to sonic-net/sonic-py-swsssdk
that referenced
this issue
Jun 1, 2022
#### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Remove python version sonic-db-cli from swsssdk. #### How to verify it Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Remove python version sonic-db-cli from swsssdk #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. --> #### A picture of a cute animal (not mandatory but encouraged)
liuh-80
added a commit
to liuh-80/sonic-swss-common
that referenced
this issue
Jun 22, 2022
…onic-net#607) Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 Re-write sonic-cli with c++. Add c++ unit test to cover all code. Pass all E2E test scenario. <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 Re-write sonic-cli with c++ for sonic startup performance issue
liuh-80
added a commit
to liuh-80/sonic-py-swsssdk
that referenced
this issue
Jun 22, 2022
#### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Remove python version sonic-db-cli from swsssdk. #### How to verify it Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Remove python version sonic-db-cli from swsssdk #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. --> #### A picture of a cute animal (not mandatory but encouraged)
liuh-80
added a commit
to sonic-net/sonic-swss-common
that referenced
this issue
Jun 23, 2022
) (#636) Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 Re-write sonic-cli with c++. Add c++ unit test to cover all code. Pass all E2E test scenario. <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 Re-write sonic-cli with c++ for sonic startup performance issue
liuh-80
added a commit
to sonic-net/sonic-py-swsssdk
that referenced
this issue
Jun 23, 2022
#### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Remove python version sonic-db-cli from swsssdk. #### How to verify it Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Remove python version sonic-db-cli from swsssdk #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. --> #### A picture of a cute animal (not mandatory but encouraged)
liuh-80
added a commit
that referenced
this issue
Jun 24, 2022
Updating sonic-utilities sub module with the following commits ca785a2 Remove sonic-db-cli #### Why I did it To fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. #### How I did it #### How to verify it #### Which release branch to backport (provide reason below if selected) #### Description for the changelog ca785a2 Remove sonic-db-cli #### A picture of a cute animal (not mandatory but encouraged) Co-authored-by: liuh-80 <azureuser@liuh-dev-vm-02.5fg3zjdzj2xezlx1yazx5oxkzd.hx.internal.cloudapp.net>
liuh-80
added a commit
to liuh-80/sonic-buildimage
that referenced
this issue
Jun 27, 2022
…ic-net#10825) Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net#10218 ETA of this issue will be 2022/05/31 Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Modify swss-common rules and slave.mk to install c++ version sonic-db-cli. Pass all E2E test scenario. <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 Build and install c++ version sonic-db-cli from swss-common. <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. -->
liuh-80
added a commit
to liuh-80/sonic-buildimage
that referenced
this issue
Jun 27, 2022
Updating sonic-utilities sub module with the following commits ca785a2 Remove sonic-db-cli To fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net#10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. ca785a2 Remove sonic-db-cli Co-authored-by: liuh-80 <azureuser@liuh-dev-vm-02.5fg3zjdzj2xezlx1yazx5oxkzd.hx.internal.cloudapp.net>
liuh-80
added a commit
that referenced
this issue
Jun 30, 2022
) (#11262) Fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 ETA of this issue will be 2022/05/31 Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Modify swss-common rules and slave.mk to install c++ version sonic-db-cli. Pass all E2E test scenario. <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 Build and install c++ version sonic-db-cli from swss-common. <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. -->
In 202111 an image built from commit 9b4387a does not execute sonic-db-cli C++ version:
|
liuh-80
added a commit
that referenced
this issue
Jul 11, 2022
Updating sonic-utilities sub module with the following commits cc847a2 Change diff coverage threshold to 80% ca785a2 Remove sonic-db-cli #### Why I did it To fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. #### How I did it #### How to verify it #### Which release branch to backport (provide reason below if selected) #### Description for the changelog cc847a2 Change diff coverage threshold to 80% ca785a2 Remove sonic-db-cli #### A picture of a cute animal (not mandatory but encouraged) Co-authored-by: liuh-80 <azureuser@liuh-dev-vm-02.5fg3zjdzj2xezlx1yazx5oxkzd.hx.internal.cloudapp.net>
itamar-talmon
pushed a commit
to itamar-talmon/sonic-swss-common
that referenced
this issue
Jul 19, 2022
…onic-net#607) #### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++. #### How to verify it Add c++ unit test to cover all code. Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Re-write sonic-cli with c++ for sonic startup performance issue
yxieca
pushed a commit
that referenced
this issue
Aug 8, 2022
Updating sonic-utilities sub module with the following commits ca785a2 Remove sonic-db-cli #### Why I did it To fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. #### How I did it #### How to verify it #### Which release branch to backport (provide reason below if selected) #### Description for the changelog ca785a2 Remove sonic-db-cli #### A picture of a cute animal (not mandatory but encouraged) Co-authored-by: liuh-80 <azureuser@liuh-dev-vm-02.5fg3zjdzj2xezlx1yazx5oxkzd.hx.internal.cloudapp.net>
yxieca
pushed a commit
to sonic-net/sonic-swss-common
that referenced
this issue
Aug 8, 2022
) #### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net/sonic-buildimage#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++. #### How to verify it Add c++ unit test to cover all code. Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Re-write sonic-cli with c++ for sonic startup performance issue
liuh-80
added a commit
to liuh-80/sonic-buildimage
that referenced
this issue
Aug 12, 2022
…ic-net#10825) Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net#10218 ETA of this issue will be 2022/05/31 Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Modify swss-common rules and slave.mk to install c++ version sonic-db-cli. Pass all E2E test scenario. <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 Build and install c++ version sonic-db-cli from swss-common. <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. -->
liuh-80
added a commit
to liuh-80/sonic-buildimage
that referenced
this issue
Aug 12, 2022
Updating sonic-utilities sub module with the following commits ca785a2 Remove sonic-db-cli #### Why I did it To fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net#10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. #### How I did it #### How to verify it #### Which release branch to backport (provide reason below if selected) #### Description for the changelog ca785a2 Remove sonic-db-cli #### A picture of a cute animal (not mandatory but encouraged) Co-authored-by: liuh-80 <azureuser@liuh-dev-vm-02.5fg3zjdzj2xezlx1yazx5oxkzd.hx.internal.cloudapp.net>
liuh-80
added a commit
that referenced
this issue
Aug 17, 2022
) (#11713) Cherry pick PR #10825 to 202205 branch #### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Modify swss-common rules and slave.mk to install c++ version sonic-db-cli. #### How to verify it Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Build and install c++ version sonic-db-cli from swss-common. #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. --> #### A picture of a cute animal (not mandatory but encouraged)
skbarista
pushed a commit
to skbarista/sonic-buildimage
that referenced
this issue
Aug 17, 2022
Updating sonic-utilities sub module with the following commits ca785a2 Remove sonic-db-cli #### Why I did it To fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net#10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. #### How I did it #### How to verify it #### Which release branch to backport (provide reason below if selected) #### Description for the changelog ca785a2 Remove sonic-db-cli #### A picture of a cute animal (not mandatory but encouraged) Co-authored-by: liuh-80 <azureuser@liuh-dev-vm-02.5fg3zjdzj2xezlx1yazx5oxkzd.hx.internal.cloudapp.net>
skbarista
pushed a commit
to skbarista/sonic-buildimage
that referenced
this issue
Aug 17, 2022
…ic-net#10825) (sonic-net#11713) Cherry pick PR sonic-net#10825 to 202205 branch #### Why I did it Fix sonic-db-cli high CPU usage on SONiC startup issue: sonic-net#10218 ETA of this issue will be 2022/05/31 #### How I did it Re-write sonic-cli with c++ in sonic-swss-common: sonic-net/sonic-swss-common#607 Modify swss-common rules and slave.mk to install c++ version sonic-db-cli. #### How to verify it Pass all E2E test scenario. #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog Build and install c++ version sonic-db-cli from swss-common. #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/SONiC/wiki/Configuration. --> #### A picture of a cute animal (not mandatory but encouraged)
liuh-80
added a commit
that referenced
this issue
Aug 22, 2022
Cherry pick PR ttps://github.com//pull/10996 to 202205 branch Updating sonic-utilities sub module with the following commits ca785a2 Remove sonic-db-cli #### Why I did it To fix sonic-db-cli high CPU usage on SONiC startup issue: #10218 sonic-db-cli re-write with c++ and move to sonic-swss-common repo. #### How I did it #### How to verify it #### Which release branch to backport (provide reason below if selected) #### Description for the changelog ca785a2 Remove sonic-db-cli #### A picture of a cute animal (not mandatory but encouraged)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
sonic-db-cli high CPU usage on SONiC startup
Steps to reproduce the issue:
Describe the results you received:
Looking at the bootchart plots we see an enormous amount of CPU time taken by sonic-db-cli.
It’s in python and most time spent in python libraries on import time. I have done some small experiment rewriting this utility in C++ (the PoC code attached) since this utility is quite simple.
It gave another 5 sec improvement and the sonic-db-cli disappeared from the plot:
Describe the results you expected:
Low CPU usage of sonic-db-cli.
Output of
show version
:Output of
show techsupport
:Additional information you deem important (e.g. issue happens only occasionally):
The text was updated successfully, but these errors were encountered: