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

Fixes #16197: Serialization of NodeConfigurations is fairly expensive #4193

Conversation

fanf
Copy link
Member

@fanf fanf commented Feb 24, 2022

https://issues.rudder.io/issues/16197

Rewrite NodeExpectedReports json serialisation with zio-json.
This is extremely boilerplaty because:

  • I wanted to kept the JsonNodeExpectedReports which is the current API with "the world outside the serialisation logic"
  • I needed to have something compatible with json from 7.0 and the new version (so that's 2x the code).

Appart the boilerplateness, it is fairly systematic. For each version, I:

  • created case classes to match the exact names of the JSON
  • for each of these case class, I define a transform method to its corresponding JsonNodeExpectedReports counterpart, and an implicit case class for the opposite operation
  • then, for each case class, I create a JsonCodec to read from/to JSON. Most are just simple derivation, some are a bit more code because our json structure is not very nice for ADT (it misses a discriminant to answer "what case class of the ADT")

And it's almost all.
There is a lot of code in tests, too, because well, I had to hand write JSON ADT to be sure the matching was OK.

The only a bit interesting part is the fallback logic: we try first version 7.1, then version 7.0 decoder (because we should converge with "everything in 7.1"). And we always encode in 7.1.

It's seems fast. 100k parse(serialise) takes 19s for a 10kB json, so with my high precision measure, 0.2 ms for a parse(serialise).
Lift was taking 10s for 10k, so that's at least 5x better.

The new version is takes around 50% less space. That should also help performances.

@fanf
Copy link
Member Author

fanf commented Feb 24, 2022

PR rebased

@fanf fanf force-pushed the arch_16197/serialization_of_nodeconfigurations_is_fairly_expensive branch from 61ae107 to dbdbb96 Compare February 24, 2022 23:18
@fanf
Copy link
Member Author

fanf commented Feb 24, 2022

PR updated with a new commit

@fanf
Copy link
Member Author

fanf commented Feb 25, 2022

PR updated with a new commit

@fanf
Copy link
Member Author

fanf commented Feb 25, 2022

PR updated with a new commit

* ]
*/

// name are false for startHour / splayHour and no override
Copy link
Member

Choose a reason for hiding this comment

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

i don't understand this comment

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, I copy/copied it. It's on the version 7 for agentrun

def transform = JsonGlobalPolicyMode7_1(x.mode, x.overridable)
}

final case class JsonModes7_1(
Copy link
Member

Choose a reason for hiding this comment

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

could you add in comment the meaning of each of the field name. It would improve readability and avoid typos

, vs: List[Either[List[String],JsonExpectedValueId7_1]]
) extends JsonComponentExpectedReport7_1 {
def transform = ValueExpectedReport(vid, vs.map {
case Left(Nil) => ExpectedValueMatch("None", "None")
Copy link
Member

Choose a reason for hiding this comment

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

can you add in the comment that the Left is for compatibility with pre-7.1 ? I've been a bit at a lost here

Copy link
Member Author

Choose a reason for hiding this comment

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

it's for compat with all techniques that don't have reportId, so more than pre-7.1, but yes I can

////////// json codec //////////

implicit val codecJsonGlobalPolicyMode7_1: JsonCodec[JsonGlobalPolicyMode7_1] = DeriveJsonCodec.gen
implicit val codecJsonAgentRun7_0: JsonCodec[JsonAgentRun7_1] = DeriveJsonCodec.gen
Copy link
Member

Choose a reason for hiding this comment

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

is it a typo ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep. The name does not matter, but it's quite misleading :)

Copy link
Member

@ncharles ncharles left a comment

Choose a reason for hiding this comment

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

This looks great, and is quite clear
I'd just like a bit more comment on the case classes, so that we don't mix up field, and I think there is a 7_0 instead of a 7_1

@fanf
Copy link
Member Author

fanf commented Feb 25, 2022

PR updated with a new commit

@Normation-Quality-Assistant
Copy link
Contributor

OK, squash merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant force-pushed the arch_16197/serialization_of_nodeconfigurations_is_fairly_expensive branch from b0cb8e3 to 39c4ee8 Compare February 25, 2022 13:52
@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 39c4ee8 into Normation:branches/rudder/7.1 Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants