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

Question: steps to production from this project #65

Open
photoszzt opened this issue Oct 9, 2020 · 4 comments
Open

Question: steps to production from this project #65

photoszzt opened this issue Oct 9, 2020 · 4 comments

Comments

@photoszzt
Copy link

I implement a lru cache based on this project. I know that this project isn't for production use. But what's the step missing for production usage? I know there're a few fix constants documented in the comments. Besides that, is there any good practice that does not exercise for this project to be ready for production usage? I'm new to tokio.

Looking at the flamegraph of the lru cache,
image
I notice that parsing the command takes a substantial time which might have room to optimize. Is there anything else that could be done better?

@Darksonn
Copy link
Collaborator

Darksonn commented Oct 9, 2020

Perhaps the most important part missing in being production-ready is an intention to support the project in the future. If someone reports an issue with this project, and we don't believe actually fixing it would improve the project in the direction of being a learning resource, it might just turn into another one of those comments you mentioned.

As for your lru frame, it seems like the parsing spends the majority of the time inside a call to Bytes::copy_from_slice.

@photoszzt
Copy link
Author

photoszzt commented Oct 10, 2020

Looking at the code,

let data = Bytes::copy_from_slice(&src.bytes()[..len]);
this is the only place that uses the function. Is there any way to optimize this part?

@Darksonn
Copy link
Collaborator

You would have to change several other parts of the codebase to elide that copy if it's possible at all.

@photoszzt
Copy link
Author

I try to make the parsing code without copy:
https://github.com/photoszzt/cache_server/blob/522a2fc3fcb8ba57fd7e24a7505b41cd60a0321e/src/frame.rs#L274-L332
I change the parse in connections.rs to https://github.com/photoszzt/cache_server/blob/522a2fc3fcb8ba57fd7e24a7505b41cd60a0321e/src/connection.rs#L102-L132

My modified version records the start and end position in the slice and uses split_to and freeze to get Bytes from BytesMut.
But I find that this modification is leaking memory. I'm running a workload that inserts key/value and deletes them. The one that uses copy_from_slice doesn't leak memory. Is there anything wrong on this modification?

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

No branches or pull requests

2 participants