How to optimally serve static files using REST API on Heroku

This question may be a bit subjective, but I think that it will offer some valuable specific information and solutions for proxying to the hero and problems with debugging delay.

I have an application built using Sinatra / Mongo that provides a REST API on api.example.com. This is on Keroka Geroku. I usually serve static files via nginx to www and proxy requests to / api to the api subdomain to avoid complaints about cross-domain browsers. I have an instance of the rackspace cloud, so I temporarily put the front-end on nginx and install a proxy server. Now latency is terrible when proxying, every 3 or 4 requests takes more than 1 minute, otherwise - 150 ms. When switching directly to the API (browser on api.example.com), the average latency is ~ 40 ms. Although I know that the installation is not perfect, I did not expect it to be so bad.

I assume that this is partly due to proxying from rackspace - the server may well be on the west coast - the hero on amazon ec2 east. My idea at the moment is that getting an instance of amazon ec2 and proxying this application for my hero will ease the problem, but I would like to somehow check it, rather than guessing blindly (this is also more expensive). Is there any reasonable way to determine where long latency comes from? Also, any other suggestions on how to structure this application? I know that I can serve static files on Heroku, but I don’t like the idea of ​​my API serving my front-end, rather, they can scale independently.

+3
source share
1 answer

Heroku API, Amazon S3, - "myapp-static", Amazon Cloudfront DNS CNAME (static.myapp.com).

S3 Rackspace :

  • Heroku, (AWS).
  • S3 .

Cloudfront , , ( HTTP-), , . EG: API , AWS California, Heroku.

, , LINK (: http://static.myapp.com/images/background.png) REST API, , .

+3

All Articles