Web 服务中序列化的成本

发布于 2024-09-26 15:51:59 字数 407 浏览 5 评论 0原文

我的下一个项目涉及在企业框架内创建数据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白况 2024-10-03 15:51:59

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.

记忆之渊 2024-10-03 15:51:59

我们提供 XML 和 JSON。您提到的渲染时间确实可能是一个问题。在服务器端,我们有 JAXB,当涉及到 marshall XML 时,其标准 sun 实现有点慢。 XML 的缺点是冗长,但在互操作性方面也很好,并且具有模式 + 显式版本控制。

我们通过多种方式补偿了冗长(特别是限制结果集):

  • 如果您有一个包含项目的容器,请在 xml 响应中提供分页(页面大小和页码,例如 /items?page=0& ;大小=3) 。客户端本身可以通过减小页面大小来减小大小。
  • 提供折叠元素,例如,多个客户只对整个项目的一个数据字段感兴趣。使用参数(例如 /items?select=name)执行此操作,然后只有嵌套元素“name”包含在 item 元素的内联中。这极大地减小了尺寸。

通常赋予客户端使用结果集限制的权力。他们肯定会使用它,因为它也加快了他们的响应时间:)

还使用压缩,它极大地减少了冗长的 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):

  • In case you have a container with items in it, offer paging in your xml response (both page-size and page-number, e.g. /items?page=0&size=3) . The client can itself reduce the size by reducing the page-size.
  • Offer collapsing elements, for instance several clients are only interested in one data field of your whole item. Do this with a parameter (e.g. /items?select=name), then only the nested element 'name' is included inline of your item element. This dramatically decreases size.

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

对你的占有欲 2024-10-03 15:51:59

我想提供三个指导方针:

  1. 一是观察到有许多 SOAP Web 服务(特别是使用 .NET 2.0“ASMX”技术构建的),它们发送在其中序列化的数据传输对象 XML。当然,有许多 RESTful 服务可以发送 XML 或 JSON。 XML 序列化/反序列化很少是限制因素。
  2. Web 服务瓶颈的一个常见原因是接口鼓励客户端应用程序通过进行数千个顺序调用来获取数据(有一个术语:闲聊接口)。这是您在设计 Web 服务界面时应该避免的情况,无论您决定使用什么四个字母的缩写词。
  3. 关于 REST 需要记住的一件事是,它(部分)代表状态传输,这可能不适合某些您不想将业务对象的状态从服务器传输到客户端应用程序的操作。在这些情况下,SOAP Web 服务(如您的同事所建议的)更合适;或者可能是 SOAP 和 REST 服务的组合,其中 REST 服务将处理适合状态传输的操作,而 SOAP 服务将实现其余操作(双关语无意:-))。

I'd like to offer three guidelines:

  1. one is the observation that there are many SOAP Web services out there (especially built with .NET 2.0 "ASMX" technology) that send down their data transfer objects serialized in XML. There are of course many RESTful services that send down XML or JSON. XML serialization/deserialization is rarely the constraining factor.
  2. one common cause of bottlenecks in Web services is an interface that encourages client applications to get data by making those thousands of sequential calls (there is a term for it: a chatty interface). This is what you should avoid when you design your Web service's interface, regardless of what four-letter acronym you decide to go ahead with.
  3. one thing to remember about REST is that it (partially) stands for a transfer of state, which may be ill-suited to some operations where you don't want to transfer the state of a business object from the server to a client application. In those cases, a SOAP Web service (as suggested by your colleagues) is more appropriate; or perhaps a combination of SOAP and REST services, where the REST services would take care of operations where the state transfer is appropriate, and the SOAP services would implement the rest (pun unintended :-)) of the operations.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文