Skip to content

Commit

Permalink
[orchagent]: Add set batch size option to configure consumer table be…
Browse files Browse the repository at this point in the history
…havior (sonic-net#234)

- Add flexibility to set pop batch size for consumer table. This parameter
  affects the speed of consuming entries from the database. Use a larger
  number will force the consumer to pop out more entries from the database
  on one SPOP operation.
  • Loading branch information
Shuotian Cheng authored Jun 4, 2017
1 parent 3a9be95 commit b893b4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ sai_object_id_t gVirtualRouterId;
sai_object_id_t gUnderlayIfId;
MacAddress gMacAddress;

#define DEFAULT_BATCH_SIZE 128
int gBatchSize = DEFAULT_BATCH_SIZE;

bool gSairedisRecord = true;
bool gSwssRecord = true;
ofstream gRecordOfs;
Expand Down Expand Up @@ -177,14 +180,15 @@ string getTimestamp()

void usage()
{
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-m MAC]" << endl;
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC]" << endl;
cout << " -h: display this message" << endl;
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
cout << " 0: do not record logs" << endl;
cout << " 1: record SAI call sequence as sairedis*.rec" << endl;
cout << " 2: record SwSS task sequence as swss*.rec" << endl;
cout << " 3: enable both above two records" << endl;
cout << " -d record_location: set record logs folder location (default .)" << endl;
cout << " -b batch_size: set consumer table pop operation batch size (default 128)" << endl;
cout << " -m MAC: set switch MAC address" << endl;
}

Expand All @@ -199,10 +203,13 @@ int main(int argc, char **argv)

string record_location = ".";

while ((opt = getopt(argc, argv, "m:r:d:h")) != -1)
while ((opt = getopt(argc, argv, "b:m:r:d:h")) != -1)
{
switch (opt)
{
case 'b':
gBatchSize = atoi(optarg);
break;
case 'm':
gMacAddress = MacAddress(optarg);
break;
Expand Down
6 changes: 4 additions & 2 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

using namespace swss;

extern int gBatchSize;

extern mutex gDbMutex;
extern PortsOrch *gPortsOrch;

Expand All @@ -21,7 +23,7 @@ extern string getTimestamp();
Orch::Orch(DBConnector *db, string tableName) :
m_db(db)
{
Consumer consumer(new ConsumerStateTable(m_db, tableName));
Consumer consumer(new ConsumerStateTable(m_db, tableName, gBatchSize));
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
}

Expand All @@ -30,7 +32,7 @@ Orch::Orch(DBConnector *db, vector<string> &tableNames) :
{
for(auto it : tableNames)
{
Consumer consumer(new ConsumerStateTable(m_db, it));
Consumer consumer(new ConsumerStateTable(m_db, it, gBatchSize));
m_consumerMap.insert(ConsumerMapPair(it, consumer));
}
}
Expand Down

0 comments on commit b893b4f

Please sign in to comment.