Skip to content

Conversation

gpunathilell
Copy link

@gpunathilell gpunathilell commented Sep 18, 2025

Update pubsub class to use the same dbconnector class and use it for ConfigDbConnector listen, so that it can subscribe to multiple patterns at the same time, thereby causing it to be used only once

Test results

root@1a86774fde1b:/sonic/src/sonic-swss-common# ./tests/tests --gtest_filter="*KeySpace*" --gtest_break_on_failure
Note: Google Test filter = *KeySpace*
[==========] Running 7 tests from 2 test suites.
[ RUN      ] KeySpaceSubTestFixture.testUnSubscribe
Num Events with two Subscriber: 160
Num Events with one Subscriber: 80
[       OK ] KeySpaceSubTestFixture.testUnSubscribe (6011 ms)
[----------] 1 test from KeySpaceSubTestFixture (6011 ms total)

[----------] 6 tests from KeySpaceSubTests/KeySpaceSubTestFixtureParameterized
[ RUN      ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/0
[       OK ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/0 (2004 ms)
[ RUN      ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/1
[       OK ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/1 (2004 ms)
[ RUN      ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/2
[       OK ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/2 (2005 ms)
[ RUN      ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/3
[       OK ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/3 (2006 ms)
[ RUN      ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/4
[       OK ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/4 (2005 ms)
[ RUN      ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/5
[       OK ] KeySpaceSubTests/KeySpaceSubTestFixtureParameterized.testSubscription/5 (2007 ms)
[----------] 6 tests from KeySpaceSubTests/KeySpaceSubTestFixtureParameterized (12031 ms total)

[----------] Global test environment tear-down
[==========] 7 tests from 2 test suites ran. (18044 ms total)
[  PASSED  ] 7 tests.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gpunathilell
Copy link
Author

@qiluo-msft This is the PR which was created based on the discussion with Vivek and Sudharsan (pubsub improvement) Please review when you have time. Thank you

self.pubsub = self.get_redis_client(self.db_name).pubsub()

def subscribe(self, table, handler, fire_init_data=False):
self._ensure_pubsub()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ensure_pubsub

There is one pitfall in this solution. The redis connections are not thread safe, so each connection should be used inside each thread only. If multiple thread calling subscribe, they will share the same pubsub, which will not work.

you may consider thread local variables if you really want to achieve the optimization.

return string("value ") + to_string(index) + ":" + to_string(keyid);
}

static inline void clearDB()

Check notice

Code scanning / CodeQL

Unused static function Note test

Static function clearDB is unreachable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants