Akka Http JSON serialization is very slow












0















I'm measuring 3-4 ms serialization time of simple JSON. Is this the performance to expect from AKKA or is there something that can be done to rectify it?



case class Response(msg: String)
implicit val format = jsonFormat(Response)


def logMagnet()(t: LoggingAdapter): HttpRequest => RouteResult => Unit = {
request => {
val startTime = System.currentTimeMillis()
response => {
val total = System.currentTimeMillis() - startTime
logger.info("took $total")
}
}
}

val route = logRequestResult(LoggingMagnet(logMagnet())) {
val start = System.currentTimeMillis()
val calculateSomethings = ....
val duration = System.currentTimeMillis() - start
val response = Response("took $duration to calculate")
complete(response)
}


The time between the logged and the response is 3-4 ms consistantly for trivial serializations.










share|improve this question

























  • Since you haven't used something like JMH for benchmark I can assume that this is probably just a cold-JVM - in other words you would have to run this code many times over (let's say 100-1000 times) to simulate actual workload, where JVM optimizations kick-in.

    – Mateusz Kubuszok
    Jan 2 at 9:57











  • And which JSON serialization you used? Vanilla Akka-HTTP doesn't have any JSON serialization build-in as far as I remember, you would have to use some Spray/Play JSON or Circe or sth else.

    – Mateusz Kubuszok
    Jan 2 at 10:02













  • Are you testing a single request?

    – EmiCareOfCell44
    Jan 2 at 10:02











  • long running, also tested with JMeter and AB, using spray marshaling

    – Avner Barr
    Jan 2 at 10:03











  • I'd suggest to use json4s, and do not use curentTimeMillis. You didn't provide the code for 'calculateSomething'. It might be the slowest part of your code.

    – kardapoltsev
    Jan 2 at 11:45


















0















I'm measuring 3-4 ms serialization time of simple JSON. Is this the performance to expect from AKKA or is there something that can be done to rectify it?



case class Response(msg: String)
implicit val format = jsonFormat(Response)


def logMagnet()(t: LoggingAdapter): HttpRequest => RouteResult => Unit = {
request => {
val startTime = System.currentTimeMillis()
response => {
val total = System.currentTimeMillis() - startTime
logger.info("took $total")
}
}
}

val route = logRequestResult(LoggingMagnet(logMagnet())) {
val start = System.currentTimeMillis()
val calculateSomethings = ....
val duration = System.currentTimeMillis() - start
val response = Response("took $duration to calculate")
complete(response)
}


The time between the logged and the response is 3-4 ms consistantly for trivial serializations.










share|improve this question

























  • Since you haven't used something like JMH for benchmark I can assume that this is probably just a cold-JVM - in other words you would have to run this code many times over (let's say 100-1000 times) to simulate actual workload, where JVM optimizations kick-in.

    – Mateusz Kubuszok
    Jan 2 at 9:57











  • And which JSON serialization you used? Vanilla Akka-HTTP doesn't have any JSON serialization build-in as far as I remember, you would have to use some Spray/Play JSON or Circe or sth else.

    – Mateusz Kubuszok
    Jan 2 at 10:02













  • Are you testing a single request?

    – EmiCareOfCell44
    Jan 2 at 10:02











  • long running, also tested with JMeter and AB, using spray marshaling

    – Avner Barr
    Jan 2 at 10:03











  • I'd suggest to use json4s, and do not use curentTimeMillis. You didn't provide the code for 'calculateSomething'. It might be the slowest part of your code.

    – kardapoltsev
    Jan 2 at 11:45
















0












0








0








I'm measuring 3-4 ms serialization time of simple JSON. Is this the performance to expect from AKKA or is there something that can be done to rectify it?



case class Response(msg: String)
implicit val format = jsonFormat(Response)


def logMagnet()(t: LoggingAdapter): HttpRequest => RouteResult => Unit = {
request => {
val startTime = System.currentTimeMillis()
response => {
val total = System.currentTimeMillis() - startTime
logger.info("took $total")
}
}
}

val route = logRequestResult(LoggingMagnet(logMagnet())) {
val start = System.currentTimeMillis()
val calculateSomethings = ....
val duration = System.currentTimeMillis() - start
val response = Response("took $duration to calculate")
complete(response)
}


The time between the logged and the response is 3-4 ms consistantly for trivial serializations.










share|improve this question
















I'm measuring 3-4 ms serialization time of simple JSON. Is this the performance to expect from AKKA or is there something that can be done to rectify it?



case class Response(msg: String)
implicit val format = jsonFormat(Response)


def logMagnet()(t: LoggingAdapter): HttpRequest => RouteResult => Unit = {
request => {
val startTime = System.currentTimeMillis()
response => {
val total = System.currentTimeMillis() - startTime
logger.info("took $total")
}
}
}

val route = logRequestResult(LoggingMagnet(logMagnet())) {
val start = System.currentTimeMillis()
val calculateSomethings = ....
val duration = System.currentTimeMillis() - start
val response = Response("took $duration to calculate")
complete(response)
}


The time between the logged and the response is 3-4 ms consistantly for trivial serializations.







scala akka akka-http spray spray-json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 9:14









EmiCareOfCell44

1,275414




1,275414










asked Jan 1 at 15:06









Avner BarrAvner Barr

6,5801163123




6,5801163123













  • Since you haven't used something like JMH for benchmark I can assume that this is probably just a cold-JVM - in other words you would have to run this code many times over (let's say 100-1000 times) to simulate actual workload, where JVM optimizations kick-in.

    – Mateusz Kubuszok
    Jan 2 at 9:57











  • And which JSON serialization you used? Vanilla Akka-HTTP doesn't have any JSON serialization build-in as far as I remember, you would have to use some Spray/Play JSON or Circe or sth else.

    – Mateusz Kubuszok
    Jan 2 at 10:02













  • Are you testing a single request?

    – EmiCareOfCell44
    Jan 2 at 10:02











  • long running, also tested with JMeter and AB, using spray marshaling

    – Avner Barr
    Jan 2 at 10:03











  • I'd suggest to use json4s, and do not use curentTimeMillis. You didn't provide the code for 'calculateSomething'. It might be the slowest part of your code.

    – kardapoltsev
    Jan 2 at 11:45





















  • Since you haven't used something like JMH for benchmark I can assume that this is probably just a cold-JVM - in other words you would have to run this code many times over (let's say 100-1000 times) to simulate actual workload, where JVM optimizations kick-in.

    – Mateusz Kubuszok
    Jan 2 at 9:57











  • And which JSON serialization you used? Vanilla Akka-HTTP doesn't have any JSON serialization build-in as far as I remember, you would have to use some Spray/Play JSON or Circe or sth else.

    – Mateusz Kubuszok
    Jan 2 at 10:02













  • Are you testing a single request?

    – EmiCareOfCell44
    Jan 2 at 10:02











  • long running, also tested with JMeter and AB, using spray marshaling

    – Avner Barr
    Jan 2 at 10:03











  • I'd suggest to use json4s, and do not use curentTimeMillis. You didn't provide the code for 'calculateSomething'. It might be the slowest part of your code.

    – kardapoltsev
    Jan 2 at 11:45



















Since you haven't used something like JMH for benchmark I can assume that this is probably just a cold-JVM - in other words you would have to run this code many times over (let's say 100-1000 times) to simulate actual workload, where JVM optimizations kick-in.

– Mateusz Kubuszok
Jan 2 at 9:57





Since you haven't used something like JMH for benchmark I can assume that this is probably just a cold-JVM - in other words you would have to run this code many times over (let's say 100-1000 times) to simulate actual workload, where JVM optimizations kick-in.

– Mateusz Kubuszok
Jan 2 at 9:57













And which JSON serialization you used? Vanilla Akka-HTTP doesn't have any JSON serialization build-in as far as I remember, you would have to use some Spray/Play JSON or Circe or sth else.

– Mateusz Kubuszok
Jan 2 at 10:02







And which JSON serialization you used? Vanilla Akka-HTTP doesn't have any JSON serialization build-in as far as I remember, you would have to use some Spray/Play JSON or Circe or sth else.

– Mateusz Kubuszok
Jan 2 at 10:02















Are you testing a single request?

– EmiCareOfCell44
Jan 2 at 10:02





Are you testing a single request?

– EmiCareOfCell44
Jan 2 at 10:02













long running, also tested with JMeter and AB, using spray marshaling

– Avner Barr
Jan 2 at 10:03





long running, also tested with JMeter and AB, using spray marshaling

– Avner Barr
Jan 2 at 10:03













I'd suggest to use json4s, and do not use curentTimeMillis. You didn't provide the code for 'calculateSomething'. It might be the slowest part of your code.

– kardapoltsev
Jan 2 at 11:45







I'd suggest to use json4s, and do not use curentTimeMillis. You didn't provide the code for 'calculateSomething'. It might be the slowest part of your code.

– kardapoltsev
Jan 2 at 11:45














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996523%2fakka-http-json-serialization-is-very-slow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996523%2fakka-http-json-serialization-is-very-slow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules