【问题标题】:Performance issues with SOAP using Spyne使用 Spyne 的 SOAP 性能问题
【发布时间】:2014-04-29 12:09:07
【问题描述】:

我们在 SOAP 网络服务中遇到了性能问题。网络服务是用 Spyne 构建的。

我认为这个问题可以通过改变接口来解决,接口只会返回必要的数据,因为我们向客户端发送了大的soap对象。

例子:

我们有一个具有很多属性的织物肥皂对象,见下文:

class Fabric(ComplexModel):
   __namespace__ = 'vadain.webservice.curtainconfig'
   id = Mandatory.Integer
   "Fabric ID"
   articleNumber = String
   "Article Number"
   name = Mandatory.Unicode
   "Fabric Name"
   color = Mandatory.Unicode
   "Color"
   width = Float
   "Fabric Width"
   widthType = WidthType
   "Width Type"
   supplier = Mandatory.Unicode
   supplierId = Integer
   "Supplier"
   ETC.

还有更多!!

我们实现了两个接口搜索fabric和getfabric,见下图:

搜索面料:

@rpc(Unicode, _returns=soap.Fabric.customize(max_occurs='unbounded'))
def fabricsWithName(ctx, name):
--Code to get all fabrics with name
return fabrics

获取面料:

@rpc(Integer, _returns=soap.Fabric)
def getFabric(ctx, fabric_id):
   --Code to get fabric from ID
return fabric

灼热面料的界面正在返回面料的所有属性,但这不是必需的。可以更改为只返回结构名称和 id。

如何以一种好的方式更改此接口“fabricsWithName”将仅返回结构名称和 ID,这将解决性能问题吗?

【问题讨论】:

    标签: performance soap spyne


    【解决方案1】:

    为什么不将返回值设置为只包含你想要的类呢?

    例如

    class FabricLite(ComplexModel):
       __namespace__ = 'vadain.webservice.curtainconfig'
       id = Mandatory.Integer
    
       name = Mandatory.Unicode
    
    # (...)
    
    @rpc(Integer, _returns=FabricLite)
    def getFabric(ctx, fabric_id):
        # (...)
    

    您无需更改函数体中的任何内容,Spyne 将忽略其余数据。

    另外,我会将 getFabric 签名更改为:

    @rpc(Mandatory.UnsignedInteger32, _returns=FabricLite)
    

    让传入的值验证更加严格。

    【讨论】:

      猜你喜欢
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 2014-06-24
      • 2018-03-01
      • 2015-12-13
      相关资源
      最近更新 更多