Web 服务中序列化的成本
我的下一个项目涉及在企业框架内创建数据 API。这些数据将由在不同软件平台上运行的多个应用程序消耗。虽然我的同事普遍喜欢 SOAP,但我想使用 RESTful 架构。
大多数应用程序每次调用时只需要几个对象。然而,其他应用程序有时需要进行多次连续调用,每次调用涉及数千条记录。我担心的是表现。序列化/反序列化&我担心网络使用会出现瓶颈。如果每个请求都有很大的延迟,那么企业的所有应用都会变得迟缓。
我的恐惧是现实的吗?序列化为 XML 或 JSON 等大量格式会出现问题吗?还有其他选择吗?
过去,为了提高性能,我们必须使用“更扁平”/更精简的文件格式(例如 CSV)来进行这些大型数据传输。我如何希望使用 Web 服务获得所需的性能?
虽然我更喜欢针对 REST 的回复,但我也有兴趣了解 SOAP 用户可能如何处理这个问题。
My next project involves the creation of a data API within an enterprise framework. The data will be consumed by several applications running on different software platforms. While my colleagues generally favour SOAP, I would like to use a RESTful architecture.
Most of the applications will only need a few objects at every call. Other applications will however sometimes need to make several sequential calls each involving thousands of records. I'm concerned about performance. Serialization/deserialization & network usage are where I fear to find a bottleneck. If each request involves a large delay, all of the enterprise's applications will be sluggish.
Are my fears realistic? Will serialization to a voluminous format like XML or JSON be a problem? Are there alternatives?
In the past, we've had to do these large data transfers using a "flatter"/leaner file format such as CSV for performance. How can I hope to achieve the performance I need using a web service?
While I'd prefer replies specific to REST, I'm interested in hearing how SOAP users might deal with this as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
REST 的优点之一是您可以自由使用您喜欢的任何媒体类型。为什么不继续使用text/csv?您还可以启用 HTTP 压缩以进一步减少带宽消耗。
REST 服务非常适合利用所有不同类型的数据格式。无论哪种格式最适合您的场景。
One advantage of REST is that you are free to use whatever media type you like. Why not continue to use text/csv? You could also enable HTTP compression to further reduce bandwidth consumption.
REST services are great for taking advantage of all different kinds of data formats. Whatever format fits your scenario best.
我们提供 XML 和 JSON。您提到的渲染时间确实可能是一个问题。在服务器端,我们有 JAXB,当涉及到 marshall XML 时,其标准 sun 实现有点慢。 XML 的缺点是冗长,但在互操作性方面也很好,并且具有模式 + 显式版本控制。
我们通过多种方式补偿了冗长(特别是限制结果集):
通常赋予客户端使用结果集限制的权力。他们肯定会使用它,因为它也加快了他们的响应时间:)
还使用压缩,它极大地减少了冗长的 XML(在我们的例子中,有效负载小了 10 倍)。从客户端,您可以通过标头“Accept-Encoding:gzip”来完成此操作。如果您使用 Apache,服务器配置也很简单
We offer both XML and JSON. Your mentioned rendering time really can be an issue. On server side we have JAXB whose standard sun-implementation is somewhat slow, when it comes to marshall XML. XML has the disadvantage of verbosity, but is also nice in interoperability and has schema + explicit versioning.
We compensated the verbosity in several ways (especially limiting the result-set):
Generally give the clients the power to use result-set limiting. They will definitley use it, because it speeds up response time also on their side :)
Also use compression, it reduces verbose XML extremely (in our case the payload got 10 times smaller). From client side you can do it by header 'Accept-Encoding: gzip'. If you use Apache, server configuration is also straight-forward
我想提供三个指导方针:
I'd like to offer three guidelines: