为什么 RESTful 应用程序更容易扩展 [英] Why are RESTful Applications easier to scale

查看:29
本文介绍了为什么 RESTful 应用程序更容易扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直读到,选择 RESTful 架构的一个原因是(除其他外)为高负载的 Web 应用程序提供更好的可扩展性.

I always read that one reason to chose a RESTful architecture is (among others) better scalability for Webapplications with a high load.

这是为什么?我能想到的一个原因是,由于每个客户端都定义了相同的资源,缓存变得更容易.在第一个请求之后,后续请求由一个 memcached 实例提供服务,该实例也可以很好地水平扩展.

Why is that? One reason I can think of is that because of the defined resources which are the same for every client, caching is made easier. After the first request, subsequent requests are served from a memcached instance which also scales well horizontally.

但是你不能用传统的方法来实现这一点,在 url 中对动作进行编码,例如(booking.php/userid=123&travelid=456&foobar=789).

But couldn't you also accomplish this with a traditional approach where actions are encoded in the url, e.g. (booking.php/userid=123&travelid=456&foobar=789).

推荐答案

REST 的一部分确实是 URL 部分(它是 REST 中的 R),但 S 对于缩放更重要:状态.

A part of REST is indeed the URL part (it's the R in REST) but the S is more important for scaling: state.

REST 的服务器端是无状态的,这意味着服务器不必跨请求存储任何内容.这意味着服务器之间不必进行(大量)通信,从而使其水平可扩展.

The server end of REST is stateless, which means that the server doesn't have to store anything across requests. This means that there doesn't have to be (much) communication between servers, making it horizontally scalable.

当然,R (representational) 有一个小好处,负载均衡器可以轻松地将请求路由到正确的服务器,如果你有很好的 URL,并且 GET 可以转到从服务器而 POST 则交给主人.

Of course, there's a small bonus in the R (representational) in that a load balancer can easily route the request to the right server if you have nice URLs, and GET could go to a slave while POSTs go to masters.

这篇关于为什么 RESTful 应用程序更容易扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆