高性能REST API - 哪種語言/堆棧?

[英]High-performance REST API - Which language/stack?


I am developing a site using Ruby on Rails. I would like to develop the REST API (JSON) separately to maximize performance, the Rails stack just takes away too much.

我正在使用Ruby on Rails開發一個站點。我想分別開發REST API(JSON)以最大限度地提高性能,Rails堆棧只會帶走太多。

Are there any performance benchmarks out there? What do you think would yield the best performance? I am currently thinking about the following, because that's what I have experience with. Is there anything else I should consider? It should be lightweight.

那里有任何性能基准嗎?您認為會產生最佳表現?我目前正在考慮以下內容,因為這是我的經驗。還有什么我應該考慮的嗎?它應該是輕量級的。

  • node.js
  • Scala Spray (http://spray.io/)
  • Scala Spray(http://spray.io/)

  • Ruby Sinatra

Thanks!

4 个解决方案

#1


26  

Summary: Maximize your performance as a developer. Use stack you know best. First make it work, then make it fast.

摘要:最大化您作為開發人員的表現。使用你最了解的堆棧。首先讓它工作,然后快速。

Are there any performance benchmarks out there?

那里有任何性能基准嗎?

There are all kinds of benchmarks out there. Let's say, node.js can handle 100k HPS (helloworlds per second) and Sinatra can only do 80k. What does it tell you? Nothing.

那里有各種各樣的基准。比方說,node.js可以處理100k HPS(每秒helloworlds),而Sinatra只能處理80k。它告訴你什么?沒有。

Also, sometimes higher performance comes at a great cost. Take ruby C extensions, for example. Sure, C runs faster than Ruby, but it prevents other threads from running on other cores (because of GIL).

此外,有時更高的性能需要付出巨大的代價。以ruby C擴展名為例。當然,C運行速度比Ruby快,但它阻止其他線程在其他核心上運行(因為GIL)。

So, don't choose tech only by benchmark figures from the internet. There are so many factors to consider besides raw HPS number.

所以,不要只選擇來自互聯網的基准數據。除原始HPS數量外,還有許多因素需要考慮。

LINK: If you think Rails is too heavy, you should try rails-api. It's basically a stripped down version of Rails (you don't need things like cookie authentication or MSIE rendering helpers in an api server).

鏈接:如果您認為Rails太重,您應該嘗試使用rails-api。它基本上是Rails的精簡版本(你不需要像api服務器中的cookie身份驗證或MSIE渲染助手那樣的東西)。


Personal story

I run an API server that handles some load. First version was written with Rails. Then I thought "Hey, Rails Is Bloated (c), let's rewrite everything with Sinatra". And then I had waves of frustration coming one after another. It turned out that Rails does a lot of small but helpful things which I didn't appreciate. I gave up, rewrote it with Rails again (applying lessons learned) and lived happily ever since.

我運行一個處理一些負載的API服務器。第一個版本是用Rails編寫的。然后我想“嘿,Rails臃腫(c),讓我們用Sinatra改寫一切”。然后我一個接一個地沮喪地揮之不去。事實證明,Rails做了很多小但有用的事情,我並不欣賞。我放棄了,再次用Rails重新編寫它(應用經驗教訓)並從此過上幸福的生活。

#2


3  

This falls into the 'should I rewrite my apache/php site in C with a customized webserver because it's slow' bucket.

這應該是'我應該用C語言服務器重寫我的apache / php網站,因為它很慢'。

I vote for picking your favorite stack to work in and utilize good caching and using whatever opcode optimization you've available if your code isn't compiled. Then make sure you've got adequate server resources and load balance horizontally if needed to handle the traffic.

我投票選擇你最喜歡的堆棧,並利用良好的緩存,並使用你可用的任何操作碼優化,如果你的代碼沒有編譯。然后,如果需要處理流量,請確保您已獲得足夠的服務器資源和水平負載平衡。

I've yet to see many API's whose primary reason for poor performance is the choice of technology stack unless they're handling facebook/twitter size traffic or doing computationally intensive work.

我還沒有看到許多API,其性能不佳的主要原因是技術堆棧的選擇,除非他們處理facebook / twitter大小流量或進行計算密集型工作。

You'll see in just about any stack you choose if properly utilized more latency occur in:

您可以在幾乎任何堆棧中看到,如果使用得當,可能會出現更多延遲:

  1. Transport of unnecessarily large amounts of data to the client
  2. 將不必要的大量數據傳輸到客戶端

  3. Performance hits due to poor SQL or other data source fetching slowness
  4. 由於SQL或其他數據源的緩慢導致性能下降

I'd also highly recommend if you're already using a RoR stack to stick with it. Trying to optimize and code in different stacks will generally result in weaker code in both--keep your dev's brains focused in one pool of futz at a time.

如果你已經使用RoR堆棧堅持下去,我也強烈推薦。嘗試優化和編碼不同的堆棧通常會導致兩者中的代碼較弱 - 讓你的開發人員的大腦一次集中在一個futz池中。

#3


1  

It really depends on your usecases and team experience/preferences - BUT, if you are truly open-ended about whatever stack, our personal experience was:

這真的取決於你的用例和團隊經驗/偏好 - 但是,如果你對任何堆棧真的是開放式的,我們的個人經驗是:

  • Scala + Scalatra + Jetty was simple and very fast.
  • Scala + Scalatra + Jetty簡單而且非常快。

  • Node + Express was surprisingly close in speed - but with the benefit (in our case) of flexible Javascript code.
  • Node + Express的速度令人驚訝地接近 - 但具有靈活的Javascript代碼的好處(在我們的例子中)。

  • Ruby was much less performant than either, but had cool code.
  • Ruby的性能要低得多,但代碼很酷。

Scala was a winner because our shop has lots of experience in the JVM. Hoever, we hope to leverage node more in the future do to the simplicity.

Scala是贏家,因為我們的商店在JVM方面擁有豐富的經驗。不過,我們希望將來更多地利用節點做到簡單。

I'm sure experienced Ruby guys could do improve and tune things, but it wasn't worth the learning-curve for us and a non-starter.

我確信經驗豐富的Ruby人員可以做些改進和調整的事情,但對我們來說並不值得學習曲線和非首發。

#4


1  

Check out spray -- I like it because it is lightweight and well-designed (modular, asynchronous, sane API). For web service stuff most web frameworks just come with too much baggage.

檢查噴霧 - 我喜歡它,因為它重量輕,設計精良(模塊化,異步,理智的API)。對於Web服務而言,大多數Web框架都帶有太多的包袱。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/11/30/72f30c23c93450c80b70744a7c831ad9.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com