JSON或HTML:哪种输出效果更好? [英] JSON or HTML: Which output can perform better?

查看:158
本文介绍了JSON或HTML:哪种输出效果更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑通过将渲染移至客户端来提高网站性能.当前堆栈为:(router, sphinx, db) + HTML.我正在考虑将其更改为:(router, sphinx, db) + JSON.

I am thinking of improving website performance by moving rendering to the client side. The current stack is: (router, sphinx, db) + HTML. I am thinking of changing this to: (router, sphinx, db) + JSON.

所有客户端都运行i7处理器,他们不太在意客户端渲染性能.我们还提供了客户端应用程序,可以连接到可靠的JSON API(这不涉及客户端与服务器端渲染的讨论).

All of clients are running i7 processors and they don't care much about client side rendering performance. We also have client side app which is ready to connect to resful JSON API (this is not to go into discussion about client vs server side rendering).

1)服务器上的渲染大约需要20%的时间(其中80%用于路由,sphinx,db).我听说输出JSON花费的时间大约是输出HTML的一半,因此我认为它将提高10%,而这10%可以用于数据处理.我说得对吗?

1) Rendering on server takes about 20% of time (and 80% goes to routing, sphinx, db). I heard that outputting JSON takes about half of the time that it takes to output HTML, so I think it would be 10% improvement, and those 10% could go into data processing. Am I right about that?

2)我认为一台服务器的性能提高10%意味着,要使具有100台物理服务器的大型应用程序获得相同的性能,我们需要的服务器数量减少10%:在这种情况下,服务器数量减少了90%,而不是100.这个正确吗?

2) I believe that 10% improvement for one server means that, to get the same amount of performance with a large scale app with 100 physical servers, we need 10% less servers: in this case 90 instead of 100. Is this correct?

3)如何在Ruby中获得最佳性能以输出JSON而不是其他任何格式?

3) How is it possible to get the best performance in Ruby to output JSON instead of any other format?

4)在日常情况下,如果我们输出JSON而不是HTML,那么在性能上会有什么不同?

4) Taking daily scenarios, what difference could be made performance wise if we output JSON instead of HTML?

推荐答案

1,2)可能是的,但是可能存在无法计算的因素,这可能会使性能提高幅度低于您的预期.就像,如果瓶颈是IO,并且HTML创建可能受CPU限制,那么减少CPU负载只会让CPU闲置更多.真正找出答案的唯一方法是在运行并行请求处理时获得可靠的基准,并获得实际数字.

1, 2) Probably yes, but there could be uncounted for factors, which may make the performance increase to be less than you expect. Like, if bottleneck is IO, and as HTML creation probably is CPU-limited, then reducing CPU load will only let CPUs idle more. Only way to find out really is to have reliable benchmarks while running parallel request handling, and get hard numbers.

此外,花时间开发客户端渲染可能比花更多的钱来花更多的钱,而不是仅仅花更多的钱购买服务器...摩尔定律仍然成立,对这样小的改进进行这种优化可能不值得.开发成本...将这些开发人员资源集中在可以增加收入的事情上,而不是尝试少量节省,可能更好.

Further, spending the hours to develop client-side rendering might be more expensive, than just paying for more server capacity... Moore's law is still holding, doing that kind of optimization for such a small improvement is probably not worth the development cost... Probably better to concentrate those dev resources on something which would increase revenue, instead of trying to make small savings.

3)JSON生成可能使用本机库,而HTML生成是在Ruby脚本代码中进行的.而且本机代码通常比低级操作时的解释(而不是JIT编译)代码快1-2个数量级.操作级别越高,差距就越小,因此,如果"generate JSON"是高级操作,那么从Ruby或编译后的语言代码调用它同样快.

3) JSON generation probably uses a native library, while HTML generation happens in Ruby script code. And native code is typically 1-2 orders of magnitude faster than interpreted (and not JIT-compiled) code at low level operations. The higher level operation it is, the narrower the gap, so if "generate JSON" is the high level operation, then it's equally fast if you call it from Ruby or from compiled language code.

4)好吧,不确定我是否理解这个问题,但请参见答案1,2 ...

4) Well, not sure I understand the question, but see answer 1,2...

这篇关于JSON或HTML:哪种输出效果更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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