3

We're using Testem to serve a bunch of HTML files (templates). Under the covers Testem uses the "res.sendfile" method of Express to send the static file back to the client. On Mac machines this is very fast - 1-2 ms per file according to the Chrome network trace. On an Ubuntu machine, however, it takes 39ms.

This is on the latest stable Node - 0.10.29. Testem is using Express 3.1.

Any suggestions on what might cause this or how I can diagnose it further?

Kevin Dente
  • 25,430
  • 7
  • 43
  • 47
  • 1
    Caveats: I know exactly nothing about Testem; but as a complete outsider, here's what I see missing from your question: Are both Mac and the Ubuntu machine running the same version of node.js? Is the Mac version installed through HomeBrew? If you send 1 file; do you get the same result per file than if you send multiple files? If you do a traceroute from each machine, what are the results -- do they take the same network paths (all else being equal)? Is the Ubuntu machine a VM or a box? What else would we need to try to reproduce this? – George Stocker Jun 13 '14 at 21:06
  • Yeah it's odd that it seems to resolve so much faster in OSX, is the Ubuntu env some remote server or a local machine? – jiminikiz Jun 13 '14 at 21:19
  • @GeorgeStocker - same version of Node (managed through Nave, not Homebrew). Ubuntu is bare metal, no VM. I'll have to see if I can cut down the scenario to make a simple repro. – Kevin Dente Jun 16 '14 at 17:28

1 Answers1

0

I typically serve static files directly using:

app.use( express.static(__dirname+'/public') );

middleware. Your static files would be stored in

/<app-path>/public

This will allow you to access /<app-path>/public/some.html at:

http://yoursite.com/some.html

If you put file.html in /<app-path>/public/html/, the following would resolve:

http://yoursite.com/html/file.html

http://yoursite.com/public/html/file.html

If the desired result is to have clean urls without extensions, then my suggestion will not do. However, if you don't mind file extensions within urls, the static middleware should reduce request times, maybe even dramatically. Also, maybe a templating engine like dust or jade may help? It would allow you to use the res.render fn.

The thing is, I have seen request times increase when using:

res.sendfile(somepath +'/some.html');

Because express will pass that through its regex path resolution middleware before serving the file. If you have a ton of routes, that may also be slowing down request times.

Hope that helps!

jiminikiz
  • 2,867
  • 1
  • 25
  • 28
  • Why would the regex path resolution be slower on Linux vs OS X though? – Kevin Dente Jun 16 '14 at 17:28
  • I don't think regex would be slower from OS to OS, but I do know that sendfile() vs. serving a static file is slower. This seems like a tough one to solve and to isolate what exactly is different between running your express app in OSX vs. Ubuntu. Maybe you could try running the app using the express debugger? `DEBUG=express:* node app.js` – jiminikiz Jun 17 '14 at 19:08