Improving template load performance

18 views
Skip to first unread message

Ramkrishna Kulkarni

unread,
Dec 14, 2015, 7:03:57 AM12/14/15
to Nitrogen Project / The Nitrogen Web Framework for Erlang
Hello,

When I return just "hello" in the module, I get around 15K requests per second with wrk. But when I load a simple template I get around 8.5K r.p.s.  Even though the templates are cached, the templates are being checked for modification. When I disabled that check, I get around 10.5K requests per second.

Are there any other optimisations that I can do w.r.t to templates so that they load faster?


--- case #1 - return hello ---

➜  oex git:(master) ✗ wrk -c100 -t4 -d10S --timeout 2000 "http://127.0.0.1:8000/index"
Running 10s test @ http://127.0.0.1:8000/index
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.00ms    5.69ms 103.85ms   95.66%
    Req/Sec     3.82k   468.50     6.79k    92.04%
  152938 requests in 10.10s, 54.69MB read
Requests/sec:  15140.54
Transfer/sec:      5.41MB



--- case #2 - simple template ---
➜  oex git:(master) ✗ wrk -c100 -t4 -d10S --timeout 2000 "http://127.0.0.1:8000/hello?mode=template"
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    39.49ms   71.05ms 318.15ms   86.47%
    Req/Sec     2.48k     0.93k    3.88k    80.00%
  85915 requests in 10.01s, 78.08MB read
Requests/sec:   8579.02
Transfer/sec:      7.80MB



--- case #3 - simple template (modification check disabled) ---
➜  oex git:(master) ✗ wrk -c100 -t4 -d10S --timeout 2000 "http://127.0.0.1:8000/hello?mode=template"
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    50.40ms  158.01ms 965.50ms   93.08%
    Req/Sec     2.89k   331.91     3.85k    94.78%
  105179 requests in 10.01s, 95.59MB read
Requests/sec:  10508.69
Transfer/sec:      9.55MB


Ram

Jesse Gumm

unread,
Dec 14, 2015, 8:50:56 AM12/14/15
to nitrogenweb
Hi Ram,

This is something I've got improved in a branch that will be version 2.4.

I got a little side-tracked this fall and haven't had a chance to
*finish* it, though I do have it running in production in a few sites
without problem.

nitrogen_core: https://github.com/choptastic/nitrogen_core/commit/d8c48596ca2667468c6fc27df2765617a7945cdb

Add this dependency to your rebar.config:

{simple_cache, "", {git, "git://github.com/nitrogen/simple_cache",
{branch, master}}}

I'm curious to hear how these changes work for you. I was able to
improve performance by an order of magnitude with those changes.

-Jesse
> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nitrogenweb...@googlegroups.com.
> To post to this group, send email to nitro...@googlegroups.com.
> Visit this group at https://groups.google.com/group/nitrogenweb.
> For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Ramkrishna Kulkarni

unread,
Dec 14, 2015, 10:51:57 AM12/14/15
to nitro...@googlegroups.com
Hi Jesse,

These are the results with refactor branch

--- case #4 - refactor branch ---

➜  oex git:(master) ✗ wrk -c100 -t4 -d10S --timeout 2000 "http://127.0.0.1:8000/hello?mode=template"
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     9.71ms    2.73ms  27.65ms   77.63%
    Req/Sec     2.59k   153.96     3.09k    75.25%
  102955 requests in 10.01s, 100.91MB read
Requests/sec:  10289.53
Transfer/sec:     10.08MB


--- case #5 refactor branch (file modification check disabled) ---

➜  oex git:(master) ✗ wrk -c100 -t4 -d10S --timeout 2000 "http://127.0.0.1:8000/hello?mode=template"
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     9.74ms    2.65ms  37.70ms   78.84%
    Req/Sec     2.58k   136.19     3.04k    69.25%
  102741 requests in 10.01s, 100.70MB read
Requests/sec:  10266.20
Transfer/sec:     10.06MB


So, refactor does improve template load time by default without having to disable file modification check.

I'm testing another case where requests per second decreases gradually to almost half of the first run when the test is repeated several times. I'll float a separate thread on that when I have more.

Thanks a lot!


Jesse Gumm

unread,
Dec 14, 2015, 11:08:55 AM12/14/15
to nitrogenweb

Cool, thanks!

I look forward to your response.

-Jesse

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Reply all
Reply to author
Forward
0 new messages