Skip to content
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

[Improvement] Make codec to be a singleton. #389

Closed
2 of 3 tasks
xianjingfeng opened this issue Dec 7, 2022 · 11 comments · Fixed by #840
Closed
2 of 3 tasks

[Improvement] Make codec to be a singleton. #389

xianjingfeng opened this issue Dec 7, 2022 · 11 comments · Fixed by #840
Assignees
Labels
good first issue Good for newcomers

Comments

@xianjingfeng
Copy link
Member

Code of Conduct

Search before asking

  • I have searched in the issues and found no similar issues.

What would you like to be improved?

Codec will be created for many times. We should make codec to be a singleton.

public static Codec newInstance(RssConf rssConf) {
Type type = rssConf.get(COMPRESSION_TYPE);
switch (type) {
case ZSTD:
return new ZstdCodec(rssConf.get(ZSTD_COMPRESSION_LEVEL));
case SNAPPY:
return new SnappyCodec();
case NOOP:
return new NoOpCodec();
case LZ4:
default:
return new Lz4Codec();

How should we improve?

Make codec to be a singleton.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@xianjingfeng xianjingfeng added the good first issue Good for newcomers label Dec 7, 2022
@jerqi
Copy link
Contributor

jerqi commented Dec 7, 2022

Will it be thread safe?

@xianjingfeng
Copy link
Member Author

Will it be thread safe?

Yes. In fact, the underlying codec is also a singleton.

@jerqi
Copy link
Contributor

jerqi commented Dec 7, 2022

cc @zuston

@zuston
Copy link
Member

zuston commented Dec 7, 2022

The zstd and snappy codec looks OK of singleton. But LZ4Codec looks unsupported.

@xianjingfeng
Copy link
Member Author

But LZ4Codec looks unsupported.

It seems that LZ4Codec is also singleton

@tobehardest
Copy link
Contributor

I'm a newbie and I want to try to solve this problem, is it possible?

@jerqi
Copy link
Contributor

jerqi commented Mar 16, 2023

I assign this issue to you. You can have a try.

@jerqi
Copy link
Contributor

jerqi commented Mar 16, 2023

The zstd and snappy codec looks OK of singleton. But LZ4Codec looks unsupported.

lz4/lz4-java#82 Lz4 is thread safe. So it could be an singleton.

@jerqi
Copy link
Contributor

jerqi commented Apr 18, 2023

I'm a newbie and I want to try to solve this problem, is it possible?

Do you need any help from me?

@tobehardest
Copy link
Contributor

I'm a newbie and I want to try to solve this problem, is it possible?

Do you need any help from me?
Maybe i need.

@jerqi
Copy link
Contributor

jerqi commented Apr 24, 2023

I'm a newbie and I want to try to solve this problem, is it possible?

Do you need any help from me?
Maybe i need.

@tobehardest Do you know Singleton pattern? There is an example https://github.com/apache/incubator-uniffle/blob/master/internal-client/src/main/java/org/apache/uniffle/client/factory/ShuffleManagerClientFactory.java . You can refer to it.

The document is also useful for newbie. https://github.com/apache/incubator-uniffle/blob/master/CONTRIBUTING.md

jerqi pushed a commit that referenced this issue Apr 25, 2023
### What changes were proposed in this pull request?
Codec will be created for many times. We should make codec to be a singleton.  I make codec to be a singleton.

### Why are the changes needed?
Fix: #389

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
  UT

Co-authored-by: tobehardest <cvchen587@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants