HTTPService 向服务器发送 10000 行 XML 非常慢
我有一个 Flex 应用程序,允许用户创建一些内容。然后,此内容将通过 xml 发送回服务器:
private function saveBackXMLToServer():void {
var params:Object = {};
params["xml_file"] = XML_content();
http_Service.send(params);
}
我的问题是,这种方式的数据传输非常慢... 10'000 行 XML 需要大约 20 秒... 这怎么可能做得更好吗?
提前致谢!
马库斯
更新:大家好,感谢您的所有评论。我正在尝试遵循您的所有提示,但它们似乎并不容易更改。我的代码是以无法访问每个对象并保存它的方式完成的。所以我所做的就是用一个 xml 加载 swf 文件,并在运行后返回整个 xml。我的猜测是,时间并没有花在将这些线路传输到 Web 服务器上(这个任务通常很快就能完成),我认为 HTTPService 的发送函数上发生了一些事情,每个对象都必须在发送之前进行更改...
UPDATE2:我刚刚意识到这不是 Flex 应用程序的问题,而是 Rails 应用程序的问题。它接收一个 700 KB 的字符串。我想这不是为了处理这样的对象而完成的。那怎么运输呢?我尝试使用文件上传但无法完成...... 发生错误 2037!我会继续努力。
I have a flex app which allows user to create some content. this content will then be sent via xml back to the server:
private function saveBackXMLToServer():void {
var params:Object = {};
params["xml_file"] = XML_content();
http_Service.send(params);
}
My problem is, that the transport of the data this way is very slow... It takes about 20 sec for 10'000 lines of XML... How can this be done better?
Thanks in advance!
Markus
UPDATE: Hi guy's Thanks for all your comments. I'm trying to follow all of your hints, but they don't seem to be simple to change. My code is done in a way that I can't get access to every Object, and save it. So what I do is to load the swf file with one xml, and return the whole xml after I run it. My guess is, that the time isn't spent on transporting those lines to the web server (this task gets done quickly normally), I thing that there happens something on the send function of the HTTPService that every object must get changed, before sending...
UPDATE2: I just realized that it is not a matter of the flex app it is a matter of the rails app. It receives a 700 KB String. I guess it is not done for handling such a object. How to transport it then? I tryed to work with the file upload but couldn't get it done...
Error 2037 was occuring! I'll go on trying.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我强烈建议使用 AMF 而不是 XML,我相信 20 秒可以缩短到几秒甚至更短。有适用于所有语言 PHP、Ruby、Java、Python 的 AMF 库。切换并不难,并且会提高应用程序的性能
I highly recommend using AMF instead of XML I believe the 20 seconds can be shrunk to few seconds or even less. There are AMF libraries for all languages PHP, Ruby, Java, Python..It's not that hard to switch over and it will improve the performance of you app
您可以将数据分解成更小的部分。这可以通过分解您已经发送的 xml 或使用 json (或某种压缩格式)来完成。
You can break the data down into smaller pieces. That can be done by breaking apart the xml you are already sending or perhaps use json (or some compressed format) instead.
你想过使用 blazeDS 吗?
我认为,如果您仍然可以对您的应用程序进行重大更改,那就去做吧!
使用 blazeDS,您与服务器的通信速度快得多,几乎快了 10 倍!
这里有一个有用的链接:adobe blazeDS 教程
如果您需要任何帮助如何使用请写信给我。
did you thought using blazeDS?
I think that if you still can make big changes on your app just do it!
with blazeDS you get much much faster communication with server, almost x10 faster!
here a useful link: adobe blazeDS tutorial
if you need any help of how to use it just write me.
也许对于很大的数据,您可以将其打包并使用文件上传(FileReference::upload)来获得更好的吞吐量。
或者
查看 Actionscript 的一些 LZW 压缩库。我知道使用 WebService WSDL XML 数据,我能够将 500KB 的数据压缩到 40KB 左右。
Maybe for data that large you could packaging it up and using File upload (FileReference::upload) to get better throughput.
OR
Look at some of the LZW compression libraries for Actionscript. I know with WebService WSDL XML data, I was able to compress 500KB of data down to something like 40 KB.
我终于以或多或少的好方式解决了这个问题。
问题是,rails 在挂起带有小参数的请求时非常有效,但是如果您将 xml 文件放入参数中,则速度非常慢...
由于无法将 xml 文件放入文件中来发送它,所以我们只是使用机架中间件将请求放入服务器上的文件中。
不管怎样,谢谢你的回答!
马库斯
I finally solved the issue in a more or less nice manner.
The problem is, that rails is very efficient in hangling requests with small parameters, but it is extremely slow if you put a xml file in a parameter...
As there is no way to put the xml in a file to send it, we just used rack middleware to put the request in a file on the server.
Thanks for your answers anyway!
Markus