-
Notifications
You must be signed in to change notification settings - Fork 189
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
more efficient serialization of initial state for new worker #1039
Conversation
actually, optimizing worker creation with protobuf does not mean we have to merge this protobuf PR that changes channel behaviour and passes ServerConfig to the worker : Pull request #1000 changes the type of Config that is passed to the worker, and passes it with a protobuf channel. The fix of this PR here deals with a temporary file that is read only by the new worker process. We could write protobuf-serialized data in there. The two pull requests are unrelated. |
This fix here could be improved further by replacing JSON serialization with protobuf, but since it's a protobuf change, it could be done in the big protobuf PR later on. |
new function read_requests_from_file Now, creating a new worker means writing ConfigState as requests in a file, and parsing them when starting the new worker. Previously, writing/reading the ConfigStated into a file was done with serde_json reader and writer, which was inefficient.
4006aeb
to
3a4e4fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Tested with a state that contains 350k requests and 15k certificates. |
fix perf issue when creating new worker
As pointed out in #1038, creating a new worker involves writing the config state on a file using
serde_json::to_writer
:sozu/bin/src/worker.rs
Line 308 in 757a6f1
and conversely, using
serde_json::from_reader
to read the file again, from the new worker process:sozu/bin/src/worker.rs
Line 220 in 757a6f1
which leads to performance issues, especially when the state is big.
This PR fixes this issue by using the same logic as in command
sozu state save
: convert the ConfigState to WorkerRequests and write them in a file, using a big buffer. Then parse it using nom to retrieve the requests.This means changing the signature of functions that create workers. Instead of getting a ConfigState, they get
Vec<WorkerRequest>
.Gain in performance
Sōzu 0.15.17
Sōzu 0.15.17 with the fix
We do observe a doubling of performance, which is nice, but still improvable if we would serialize/parse the requests using protobuf (roughly and additionnal x2 increase in perf).