简体   繁体   English

Google Cloud Endpoints中的JSON解析速度非常慢

[英]JSON parsing very slow in Google Cloud Endpoints

Google Cloud Endpoints suggests the use of GsonFactory or JacksonFactory to do the JSON parsing. Google Cloud Endpoints建议使用GsonFactory或JacksonFactory进行JSON解析。

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. 我发现从我的端点解析几个1000个Java对象(每个对象只有几个long和string字段以及一个GeoPt字段)需要很长时间,在Galaxy Note 2上大约需要15秒。

As suggested by Google, I use: 根据Google的建议,我使用:

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

... ...

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

I get the same performance with JacksonFactory(). 我在JacksonFactory()上获得了相同的性能。

I've done some profiling and see that all the time is spent in JSON parsing. 我进行了一些分析,发现所有时间都花在了JSON解析上。

Can anyone suggest any direction here for speeding this up, other than "paging" my data fetching? 除了“分页”我的数据获取之外,有人可以在这里提出任何加快速度的建议吗?

Thanks. 谢谢。

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. 令您惊讶的是,您发现这些实现之间的速度没有差异-我认为杰克逊应该更快。

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 (eg compared to struct's). 作为具有C / C ++背景的人,Google / GAE / Endpoints交流数据的方式一直令我感到疯狂,效率低下-将二进制数据转换为文本,然后将其嵌入结构化的文本表示形式,然后进行所有解析另一端的数据(例如,与struct的数据相比)。

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. 现在,如果您只是来回发送一些对象,那实际上并不重要,但是您正在谈论解析几千个对象。

But you are not stuck with the inefficient methods just because you are using Java. 但是您不会因为使用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. Java还支持NIO(我认为GAE也支持NIO),Google还创建了协议缓冲区,该协议的缓冲区要比JSON / XML高效得多,同时仍保持语言中立。 https://developers.google.com/protocol-buffers/docs/overview https://developers.google.com/protocol-buffers/docs/overview

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. 因此,如果解析“几个1000个Java对象”对于您的应用程序来说是正常的,我建议您考虑为对象使用不同的表示形式。

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

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