1

我正在使用 Puma 和 Nginx 运行我的 Rubinius 应用程序。

我想分开我的 url 请求。

第一个用于 api 请求,第二个用于其他请求。

我认为 Puma 已经进行了线程处理,但我想确保 Web 请求不会阻塞导致我的 api 请求期间停止的线程。我想如果一个线程很忙,Puma 会创建另一个线程,但我想确保一个线程始终可用于 api 请求。

我的主要观点是为我的用户最需要的 url 请求“保存”一个线程。

谢谢你的光。

4

2 回答 2

0

由于 Puma 考虑分离线程中的每个请求,这里唯一的瓶颈是这些线程的数据库访问。除此之外,您不能保证某些线程比其他线程“更好”。

这里值得注意的一种可能的解决方案是使用nginx. 假设您的应用正在提供内容http://some_host.comAPIhttp://some_host.com/api. 您可以将您的配置为nginx单独处理请求。在这种情况下,您将需要两个单独的服务器实例。一个用于基本应用程序,一个用于 api 请求。我的意思是当一个请求到来时,它由 处理,何时由处理。http://some_host.comhttp://some_host.com/apiPumahttp://some_host.comPuma Ahttp://some_host.com/api/...Puma B

请记住一件事,您可以通过单独的实例处理请求,但您仍然只有一个数据库,除非您正在缓存内容。这里又来了一个问题。你缓存你的内容吗?如果不是,那么首先从缓存开始不是更好吗?

于 2014-10-28T16:43:44.460 回答
0

为什么不拆分主应用程序和 API?使用 Nginx 很容易为两个不同的应用程序提供服务:

  location / {
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_set_header  Host $http_host;
    proxy_redirect    off;
    proxy_pass        http://puma1;
  }


  location /api/ {
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_set_header  Host $http_host;
    proxy_redirect    off;
    proxy_pass        http://puma2/;
  }

请注意第二个位置 proxy_pass 的尾部斜杠,它有助于重写请求并省略 '/api' 前缀。

于 2014-11-09T21:00:55.357 回答