什么技术和为显示板选择的架构
对大家来说,
我实际上有两个问题:)我即将开始一个新项目,它基本上是一个显示板(类似于您在机场或证券交易所看到的东西,但有另一个目的)。它应该有许多文本项、价格标签和供选择的按钮。整个过程应该在浏览器中运行并反映实时变化(例如价格的频繁更新和项目的重新排列)。
技术
首先想到的技术是 GWT,它有助于保持低流量并允许有针对性地更新显示区域(因为渲染发生在客户端)。根据我的经验,这种选择有一些缺点:在 GWT 中从静态布局移植 HTML 和 CSS 更加耗时,因为您只能在运行时看到生成的 HTML(UiBinder 使得更方便一些,但问题很大仍然),DevMode 在 Linux 下极其缓慢,并且为单个部署编译排列可能需要几分钟的时间。所有这些都导致开发时间比 JSP 或 JSF 慢得多。
有没有其他一些在流量方面非常低调并且能够实时显示数据变化的技术或方法呢?如果某些价格标签改变了其值或在显示上的位置,我们显然不想保存整个新页面。更快的开发时间将是一种享受:)
架构
对于这种情况采用什么合适的模式。我尝试过使用一个索引对象来包含对其他价格和项目对象的引用。这样,如果屏幕上价格标签的排列发生变化,新的价格标签到达,旧的价格标签得到更新,创建新的索引对象并将其发送到客户端。客户端知道应该更新显示并重新呈现它。积极的一面是,它为您提供了许多可重用的组件(价格和项目对象),但消极的一面是,如果添加新项目,整个屏幕的重新渲染会随着更多更新的到来而变得 CPU 密集型。索引对象和页面布局之间也没有一一对应的关系:因此,如果您的设计人员选择了基于表格的布局,并且项目 1 和项目 2 之间有一个空行,那么您无法映射该项目的索引位置item 对象移动到其在所属表上的位置,无需进行任何额外处理。
我很快就会观看 GWT 上的 Google 视频之一中呈现的事件总线模式。感觉这也可能为正确的道路提供指导。
非常感谢您的建议!
更新:措辞和风格
His to everyone,
I have actually 2 questions in one :) I am about to start into a new project, which is basically a display board (similar to what you see in airports or stock exchanges but for another purpose). It should have many text items, price tags, and buttons for selection. The whole thing should run in a browser and reflect real-time changes (such as frequent updates of prices, and rearrangement of items).
Technology
First choice of technology that comes to mind is GWT that helps to keep traffic low and allows for targeted updates of display areas (since rendering happens on the client side). Based on my experience, there are some cons with this choice however: porting HTML and CSS from static layouts is much more time-consuming in GWT since you only see generated HTML at runtime (UiBinder makes is somewhat more convenient, but the problem at large remains), DevMode is excruciatingly slow under Linux and compiling a permutations for a single deploy can take minutes. Which all contributes to much slower development times than with say JSP or JSF.
Is there some other technology or approach that is very low-key in terms of traffic and is able to display data changing in a real time? We obviously don't want to save the whole new page if some price tag changes its value or position on the display. And faster development times would be a treat :)
Architecture
What would be an appropriate pattern to adopt for this case. I've tried having an index object that would contain references to other price and item objects. So that if arrangement of price tags changes on the screen, new ones arrive, old ones get updated a new index object is created and sent to the client. The client knows than that the display should be updated and renders it anew. The positive thing is that it gives you many reusable components (price and item object), on the negative side though is that this rerendering of the whole screen, if a new item is added, is becomes CPU intensive as more updates come. There is also no one-to-one correspondence between index object and layout of the page: so if you designer has chosen a table-based layout and there is one empty row between item 1 and item 2 then you cannot map index position of the item object to its position on the owning table without some additional processing.
I will be watching shortly the event bus pattern presented in one of the Google videos on GWT. Have a feeling that this might also give a guidance on the right path.
Many thanks for your suggestions!
Update: wording & style
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最近有几个人遇到了 DevMode 性能问题,我真的不确定这是为什么。根据我的经验,尤其是在 Linux 上,DevMode 非常快(事实上,我目前主要使用 Mac,而且速度慢很多。)只是为了给您一个可比较的数字:在进行代码更改后重新加载官方 StockWatcher 教程在我的 Linux 机器上大约需要一秒钟。即使对于我最大的项目(在一个页面上使用几乎极端数量的小部件),重新加载时间仍然非常好。
我真的很感兴趣,在这种情况下你会看到缓慢:在浏览器中重新加载页面时,重新启动服务器时(顺便说一句,几乎总是不必要的),重新部署服务器端时(可以很快完成,如此处所述)?我绝对推荐的一件事是使用原始的 Sun/Oracle JVM 而不是 GCJ(这通常是 Linux 上的默认设置)。还可以尝试不同的浏览器。
是的,任何使用 AJAX 和 JSON 来传输数据的东西。
实际上,StockWatcher 官方教程应该与您想要做的比较相似,即它主要显示经常更新的数据。如果您的更新不定期到达,您可能需要考虑使用 Comet 来减少请求数量,但我会从频繁轮询(如 StockWatcher)开始,然后进行微调。
UiBinder 使用innerHTML 而不是DOM 操作来修改UI,并将其与特定于浏览器的优化相结合——因此它可能是最快的。如果这些更新的性能是你所关心的,那么GWT确实是一个非常好的选择。
如果您的 UI 实际上变慢,可以在 “我应该如何使用 MVC 来加速缓慢的 GWT 应用程序”。
这取决于您使用的型号。也许与您的设计人员一起设计一个小部件(例如 MyTable.ui.xml),然后在您的 Java 类中实现相应的逻辑(如果需要复杂的映射,则不必直接在 MyTable.java 中实现)。 如果您需要针对该映射的特定问题的解决方案,最好提出一个单独的问题。
There have been several people with DevMode performance problems lately, and I'm really not sure, why that is. In my experience, especially on Linux, DevMode is very quick (in fact, I'm mostly using Mac currently, and it's a lot slower there.) Just to give you a comparable figure: Reloading the official StockWatcher tutorial after making a code change takes about one second on my Linux machine. Even with my largest project, which uses an almost extreme amount of widgets on one page, reload times are still very good.
I would be really interested, in which cases you see slowness: When reloading the page in the browser, when restarting the server (almost always unnecessary, by the way), when redeploying the server side (can be done very quickly, as explained here)? One thing I'd definitely recommend, is to use the original Sun/Oracle JVM instead of GCJ (which is often the default on Linux.) Also experiment with different browsers.
Yes, anything that uses AJAX, and JSON to transfer the data.
Actually, the official StockWatcher tutorial should be relatively similar to what you want to do, i.e. it mostly displays frequently updated data. If your updates arrive irregularly, you may want to consider using Comet to reduce the number of requests, but I'd start out with frequent polling (like StockWatcher), and fine-tune later.
UiBinder uses innerHTML instead of DOM operations to modify the UI, and it combines that with browser-specific optimizations - so it's probably as fast as it gets. If the performance of these updates is a concern of yours, then GWT is really a very good choice.
A few additional pointers that may help if your UI actually gets slow can be found in "What should I do to speed up a slow GWT app using MVC".
This depends on the model you're using. Maybe design a widget (e.g. MyTable.ui.xml) together with your designer, and then implement the according logic in your Java classes (doesn't have to be directly in MyTable.java, if complex mapping is required). If you need a solution for a specific problem with that mapping, it would probably be best to open a separate question.