简体   繁体   English

Ajax posting a complex and large object to Web API controller is very slow

[英]Ajax posting a complex and large object to Web API controller is very slow

I am post a large object with slightly complex structure via jQuery ajax to a Web API controller method but, it is very slow and it takes more than an hour for the request to reach the Web API controller method. I am post a large object with slightly complex structure via jQuery ajax to a Web API controller method but, it is very slow and it takes more than an hour for the request to reach the Web API controller method.

在此处输入图像描述

The content length is captured in the Application_BeginRequest method and it is 27505212.内容长度在 Application_BeginRequest 方法中捕获,为 27505212。

The ajax post is as shown below, ajax帖子如下图,

public static Send(request: RequestWrapper) {
    return $.ajax({
        url: 'api/MyController/methodname',
        type: 'POST',
        dataType: 'json',
        data: request
    });
}

And the controller method is as shown below,而controller方法如下图,

    [HttpPost]
    public HttpResponseMessage Send(RequestWrapper request)
    {
    }

Is there a better / simple way to do this?有没有更好/简单的方法来做到这一点? Any suggestion is greatly appreciated.非常感谢任何建议。

27 megabytes is a really big POST payload. 27 MB 是一个非常大的 POST 有效负载。 You've discovered how it's possible for a payload to be too big!您已经发现有效载荷如何可能太大!

You should break it up into much smaller chunks, maybe of no longer than 10-50k.你应该把它分成小得多的块,可能不超过 10-50k。 Then your server can reassemble the large object from the chunks.然后你的服务器可以从块中重新组装大 object。 If you're on load-balanced infrastructure that reassembly operation will make your shared session manager work really hard.如果您在负载平衡的基础架构上,那么重组操作将使您的共享 session 管理器工作非常努力。

Your best long term solution to this is to refactor your large object so it's several hundred smaller objects.您最好的长期解决方案是重构您的大型 object,使其成为数百个较小的对象。 You didn't tell us anything about the structure of your data, so it's impossible to offer suggestions on how to do that.您没有告诉我们有关数据结构的任何信息,因此无法就如何做到这一点提供建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM