JSON解析在谷歌云端点很慢 [英] JSON parsing very slow in Google Cloud Endpoints

查看:325
本文介绍了JSON解析在谷歌云端点很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌云端点建议使用GsonFactory或JacksonFactory做的JSON解析。

Google Cloud Endpoints suggests the use of GsonFactory or JacksonFactory to do the JSON parsing.

我发现,从我的端点解析数1000 Java对象(每个多头和字符串和一个类别GeoPt的只有几个字段)需要很长的,约15秒上的Galaxy Note 2。

I have found that parsing a few 1000 java objects from my endpoint (each with only a few fields of longs and strings and a GeoPt) takes very long, about 15 seconds on a Galaxy Note 2.

由于由谷歌的建议,我使用:

As suggested by Google, I use:

myBuilder = new MyDbEndpoint.Builder(
                AndroidHttp.newCompatibleTransport(),
                new GsonFactory(),
                credential);
myEndpoint = myBuilder.build();

...

List<myDb> beings = myEndpoint.myDBEndpoint().someMethod().execute().getItems();

我得到JacksonFactory()相同的性能。

I get the same performance with JacksonFactory().

我已经做了一些分析和看到所有的时间都在JSON解析度过。

I've done some profiling and see that all the time is spent in JSON parsing.

任何人都可以在这里提出任何方向加速这件事,不是传呼等我获取数据?

Can anyone suggest any direction here for speeding this up, other than "paging" my data fetching?

感谢。

推荐答案

这令我有点出人意料,你没有看到实现之间的速度差 - 我还以为杰克逊应该是更快的。

It strikes me as a bit surprising that you didn't see a difference in speed between the implementations - I thought Jackson was supposed to be faster.

离开那一边,我也不会真的希望做事要快的这整个方式。正如有人谁来自一个C / C ++的背景下,通信数据的谷歌/ GAE /端点的方式一直让我觉得疯狂低效 - 转换的二进制数据转换成文本,然后将其嵌入到结构化文本重新presentation和然后解析在另一端(例如,相比于结构体的)的所有数据。

Leaving that aside, I wouldn't really expect this whole way of doing things to be fast. As someone who comes from a C/C++ background, the Google/GAE/Endpoints way of communicating data has always struck me as crazy inefficient - converting your binary data into text and then embedding it into a structured text representation, and then parsing all that data on the other end (e.g. compared to struct's).

现在,如果你只是发送几个对象来回它其实并不重要,但你所谈论的解析数1000个对象。

Now, if you are just sending a few objects back and forth it doesn't really matter, but you are talking about parsing a few 1000 objects.

但你不坚持只是因为你使用的是Java的低效的方法。 Java还支持NIO(我觉得GAE支持它的一些),而谷歌还创建了协议缓冲区,它罢工的是更有效的JSON随后/ XML的平衡,同时仍然中性语言。
https://developers.google.com/protocol-buffers/docs/overview

But you are not stuck with the inefficient methods just because you are using Java. Java also supports NIO (and I think GAE supports some of it), and Google also created protocol buffers, which strikes a balance of being much more efficient then JSON/XML, while still being language neutral. https://developers.google.com/protocol-buffers/docs/overview

所以,如果分析少数1000 Java对象'将是正常的,你的应用程序,我建议你考虑一个不同的重新presentation为对象。

So, if parsing 'a few 1000 java objects' is going to be normal for your app, I would suggest you consider a different representation for your objects.

这篇关于JSON解析在谷歌云端点很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆