Skip to content

Improve hset and hdel performance with RedisPipeline. #647

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

Merged
merged 9 commits into from
Jul 18, 2022

Conversation

liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Jul 11, 2022

Why I did it

1.Change redis hmset command to hset because HMSET deprecated after redis 4.0.0:
https://redis.io/commands/hmset/

2.Improve DBConnector::hmset and DBConnector::del method performance.
Currently swsscommon implement hmset and del by LUA script, however change to use RedisPipeline can improve performance by 20%:

RedisPipeline hmset: 0.228743
LUA hmset: 0.260371

How I did it

Change hmset and del to use RedisPipeline.

How to verify it

Pass all test case.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jul 11, 2022

This PR just check-in test code, according to discussion result, if we decide to have this improve, we also need improve hdel and remove the lua script.

@liuh-80 liuh-80 changed the title Improve hmset with RedisPipeline [POC] Improve hmset with RedisPipeline Jul 11, 2022
@liuh-80
Copy link
Contributor Author

liuh-80 commented Jul 13, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liuh-80 liuh-80 changed the title [POC] Improve hmset with RedisPipeline [POC] Improve hmset and hdel performance with RedisPipeline Jul 13, 2022
@liuh-80 liuh-80 changed the title [POC] Improve hmset and hdel performance with RedisPipeline Improve hmset and hdel performance with RedisPipeline Jul 13, 2022
@liuh-80 liuh-80 requested review from kcudnik and qiluo-msft and removed request for kcudnik July 13, 2022 08:31
@liuh-80 liuh-80 marked this pull request as ready for review July 13, 2022 08:32
const std::vector<FieldValueTuple> &values);

template<typename InputIterator>
void formatHMSET(const std::string &key,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

formatHMSET is internal API, only use by sonic-swss-common project;
https://github.com/search?q=org%3AAzure+formatHMSET&type=code

@liuh-80

This comment was marked as resolved.

qiluo-msft
qiluo-msft previously approved these changes Jul 13, 2022
@liuh-80
Copy link
Contributor Author

liuh-80 commented Jul 14, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liuh-80 liuh-80 changed the title Improve hmset and hdel performance with RedisPipeline Change redis deprecated hmset to hset and Improve hset & hdel performance with RedisPipeline. Jul 14, 2022
@liuh-80 liuh-80 changed the title Change redis deprecated hmset to hset and Improve hset & hdel performance with RedisPipeline. Improve hset and hdel performance with RedisPipeline. Jul 14, 2022
@@ -61,6 +62,26 @@ class RedisPipeline {
return r.release();
}

redisReply *pushHSET(const std::string& key, const std::map<std::string, std::string> &values)
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 15, 2022

Choose a reason for hiding this comment

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

pushHSET

Suggest move the functionality in RedisCommand class. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, moved to RedisCommand class.

@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <queue>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

RedisPipeline using std::queue but not include the header file.
So some time when include this header file will report build error.

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jul 18, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liuh-80 liuh-80 merged commit 154cc9c into sonic-net:master Jul 18, 2022
@liuh-80 liuh-80 deleted the dev/liuh/improvehmset branch July 18, 2022 06:50
itamar-talmon pushed a commit to itamar-talmon/sonic-swss-common that referenced this pull request Jul 19, 2022
#### Why I did it
1.Change redis hmset command to hset because HMSET deprecated after redis 4.0.0:
https://redis.io/commands/hmset/

2.Improve DBConnector::hmset and DBConnector::del method performance.
Currently swsscommon implement hmset and del by LUA script, however change to use RedisPipeline can improve performance by 20%:

RedisPipeline hmset: 0.228743
LUA hmset: 0.260371

#### How I did it
Change hmset and del to use RedisPipeline.

#### How to verify it
Pass all test case.

#### 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


#### Link to config_db schema for YANG module changes

#### 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants