Pheonix REST JSON API performance

Hi, I’ve read lots of good things about Elixir and wanted to check it out. So I’ve started rewriting my REST API from Node.js, koa.js to be specific (actually it’s only GET spitting JSON). I’ve had some problems ( but it started working. To test request time I am exposing a big chunk of my db - 10MB of JSON.
What I found out is the response time is 4 times the old one (~1.5s node.js and ~6s Pheonix). Smaller chunks have about the same time (~20ms for 30KB responses).
I thought I had cache set up on my Node.js API, but that was not the case…

Could this be cause by JSON rendering?

10 MB is huge. Depending on how you build your JSON, this can involve a lot of copying binaries and memory reallocations.

Can you please tell which JSON library you use and how you render the JSON into a response?

1 Like

Do you expect to be regularly rendering 10+ MB JSON responses? If not then maybe you should try testing with a more realistic scenario.

1 Like

@NobbZ It’s just Poison, I’m using default Pheonix generated project.
@axelson Yeah, you’re right. I would need only about 0.5MB responses served, but it was just the quickest way to test it. I’m actually having quite a trouble getting to get anything running in Pheonix. Poison rendering (It keeps crashing on displaying Date (Erlang tuple)), but especially Ecto embedded queries are giving me a headache… Maybe my Schemes on Node.js scraper that upload the data into the DB is the problem.
I think it would a better idea to just a new project from scratch with Pheonix. I’ll update here if I get any new results regarding the topic.

Switching to jason is probably your best bet on making this faster. It’s many times faster than poison. It’s also the new Phoenix default albeit unreleased. You could just pull phoenix from master and try that.

Probably that could speed it up, but still, I’m currently having to many issues with actually even querying the data with Ecto, so it’s a separate issue I need to take care of before proceeding with further testing. As I said, I’ll post new results when I finally get any :slight_smile:

If you get stuck on something,be sure to post on the forum, I’m sure there will be welcoming people to help you :wink: