REST Web服务VS Socket编程为数据密集型应用程序 [英] RESTful web services vs Socket Programming for a Data Intensive Application

查看:218
本文介绍了REST Web服务VS Socket编程为数据密集型应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建设有Ruby on Rails的Web应用程序,需要具有高度可扩展性。在本申请中,数据是由移动客户端(大约20字节)每秒产生的。所有这些数据必须在某一点,preferably尽快转移到一个服务器尽可能。

I'm building a web application with Ruby on Rails which needs to be highly scalable. In this application, data is produced by a mobile client (approximately 20 bytes) every second. All of this data must be transferred to a server at some point, preferably as soon as possible.

要完成这个任务,我希望服务器充当一个RESTful服务。该客户端可以缓冲的位置(比如每5〜30秒),然后拍不送作为一个HTTP PUT请求,其中,服务器可以再保存。我相信,这种模式更容易实现,更好地处理大量的流量,因为客户可以保持缓冲数据,直到他们听到来自服务器的响应。

To accomplish this task, I want the server to act as a RESTful service. The client could buffer locations (say every 5 to 30 seconds) and then shoot them off as a HTTP put request, where the server could then store them. I believe this model is simpler to implement, and better handles high volume traffic, as the clients could keep buffering data until they hear a response from the server.

我的老板,在另一方面,希望使用套接字编程来实现服务器。他认为套接字编程将导致被传输较少的数据,这将增加系统的总效率。我无法不同意这一点,但我想给现代带宽HTTP的额外开销是值得的。另外,我想尽量保持成千上万(或上百万)的同时所连接的与用户会导致其自身的问题,大大提高了服务器的复杂性。

My boss, on the other hand, wants to implement the server using socket programming. He believes socket programming will result in less data being transferred, which will increase the total efficiency of the system. I can't disagree on this point, but I think given modern bandwidth the extra overhead with HTTP is worth it. Plus, I think trying to maintain thousands (or millions) of simultaneous connects with users will cause its own problems and greatly increase the complexity of the server.

老实说,我不知道正确的方法解决这个问题,所以我想我会在这里发表,并得到很多聪明的人比我的意见。我倒是AP preciate它,如果任何答案包括建议的解决方案的利弊。

Honestly, I don't know the right approach to this problem, so I thought I'd post it here and get the opinions of much smarter people than myself. I'd appreciate it if any answers included the pros and cons of the proposed solution.

感谢。

更新

我们现在有一些额外的要求冲出。首先,移动客户端不能上传,每月的数据超过5 GB。在这种情况下,我们谈论的一个消息第二每月每天8小时。二是我们要对信息尽可能少结合起来。这是为了确保如果事情发生在移动客户端(比如车祸),我们失去了尽可能少的数据成为可能。

We now have a few additional requirements flushed out. First, the mobile client cannot upload more than 5 GB of data per month. In this case, we're talking one message a second for eight hours a day per month. Second is we want's to combine messages as little as possible. This is to ensure if something happens to the mobile client (say a car crash), we lose as little data as possible.

推荐答案

您的老板似乎pmaturely优化$ P $,这是不是真的是一个好主意。

Your boss appears to be optimizing prematurely, which is not really a good idea.

而不是试图打一个假想的性能可怕之处之前,你甚至开始写你的code,你应该检查你的应用程序的要求而设计的给他们。不要让认识到的问题推动你的设计。

Instead of trying to fight an imaginary performance bogeyman before you've even started writing your code, you should examine your application's requirements and design to them. Don't let perceived problems drive your design.

如果说到它,有你的老板的轮廓,他究竟是如何会在他的socket连接编组数据,然后做一些快速计算,看看您是否能匹配或HTTP击败他们。他会用类似谷歌的协议缓冲器,或写他自己的封协议?如果是这样,这将是自描述?如何申请动词就像你会得到免费的HTTP什么?将他的关系是持久性?还有很多更套接字不只是打开一个连接,并喷涌字节下来了。

If it comes to it, have your boss outline exactly how he'd marshal data across his socket connection and then do some quick calculations to see if you could match or beat them with HTTP. Will he use something like Google's Protocol Buffers, or write his own marshaling protocol? If so, will it be self-describing? How about application "verbs" like what you'd get for free in HTTP? Will his connections be persistent? There's a lot more to "sockets" than just opening a connection and spewing bytes down it.

您也已经正确地指出,你的老板似乎胜于一切将有利于插座的原始速度:可扩展性,可维护性,开发和测试工具,协议嗅探器的HTTPS动词语义有所帮助,等等可用性。 HTTP是深受负载均衡和防火墙之类的理解。您的专有套接字协议将不会这么幸运。

You've also correctly noted that your boss seems to be favoring raw speed of sockets over everything else: scalability, maintainability, availability of development and testing tools, protocol sniffers, the helpful semantics of the HTTPS verbs, and so on. HTTP is well understood by load balancers and firewalls and the like. Your proprietary socket protocol will not be so lucky.

什么我建议是你看看所有的选项在那里,并从通过测试,原型设计和基准性能的角度对其进行评估。然后对建立和维持与该技术的应用的难度权衡这些数字

What I'd suggest is you look into all the options out there and evaluate them from a performance perspective through testing, prototyping and benchmarking. Then weigh those numbers against the difficulty of building and maintaining the application with that technology.

这篇关于REST Web服务VS Socket编程为数据密集型应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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