简体   繁体   English

浏览器的快速IPC方法

[英]Fast IPC method for the browser

I wrote an application that accumulates data (a few MB/sec, but updated like 10 times a second) and displays the current process in the browser via javascript. 我写了一个累积数据的应用程序(几MB /秒,但每秒更新10次),并通过javascript在浏览器中显示当前进程。

The problem is that currently I write the data to file and load it with javascript, but this makes the application very laggy and people are complaining that their hdd is working a lot. 问题是,目前我将数据写入文件并使用javascript加载它,但这使得应用程序非常滞后,人们抱怨他们的硬盘很多。

I would love to use some flags like "FILE_ATTRIBUTE_TEMPORARY" to tell my OS to not actually write the files to disk, but javascript requires me to close the file handle first (otherwise firefox couldn't open it). 我希望使用像“FILE_ATTRIBUTE_TEMPORARY”这样的标志来告诉我的操作系统实际上没有将文件写入磁盘,但是javascript要求我先关闭文件句柄(否则firefox无法打开它)。 Thus it will be written to disk at that point, killing the point in initially using that flag. 因此,它将在那时被写入磁盘,从而在最初使用该标志时消除了这一点。

I thought about using something like a mysql database, but I really want to keep it as simple as possible, and I would prefer a solution that doesn't force the user to set up some http or mysql server. 我想过使用类似mysql数据库的东西,但我真的想让它尽可能简单,我宁愿一个不强迫用户设置一些http或mysql服务器的解决方案。

Include a webserver in your standalone C++ application and serve the data directly from memory. 在独立的C ++应用程序中包含Web服务器,并直接从内存中提供数据。

I think that is the only option to avoid the I/O overhead which you are facing now. 我认为这是避免您现在面临的I / O开销的唯一选择。 There is no interface to IPC, message queues or something similar in JS. 在JS中没有IPC,消息队列或类似的东西的接口。 TCP (or UDP, with websockets) seems to be the only possible way to avoid disk I/O. TCP(或带有websockets的UDP)似乎是避免磁盘I / O的唯一可行方法。 Another option would be to replace your JavaScript with a Browser Plugin which can access the capabilities of your operating system in native code. 另一个选择是用浏览器插件替换你的JavaScript,它可以用本机代码访问操作系统的功能。

Note: In a UNIX environment, you can create a FIFO socket in the File System, which may (or may not) serve your purpose as well. 注意:在UNIX环境中,您可以在文件系统中创建一个FIFO套接字,它也可以(或可能不)为您的目的服务。 I don't think windows supports something like this, though. 我不认为Windows支持这样的东西。

It sounds like your application that accumulates data is running locally on the user's machine and that the page loaded into the browser is also local. 听起来您的应用程序累积数据在用户的计算机上本地运行,并且加载到浏览器中的页面也是本地的。 As you stated you didn't want the user to have to configure (or I would assume run) an HTTP server, that you want to avoid writing the data to disk for perf reasons, and your title includes "IPC", I believe what you are left is creating a browser plug-in or including an ActiveX control in your page. 如你所说,你不希望用户必须配置(或者我会假设运行)一个HTTP服务器,你想避免因为性能原因将数据写入磁盘,而你的标题包含“IPC”,我相信什么你剩下的就是创建一个浏览器插件或在你的页面中包含一个ActiveX控件。

An ActiveX control in your page could utilize any of the IPC mechanisms available on the platform to native code (eg shared memory). 页面中的ActiveX控件可以利用平台上可用的任何IPC机制来访问本机代码(例如共享内存)。

Another option would be to have your application be an HTTP server so a separate one was not needed, but that may be fall into the category of the user having to configure an HTTP server (they may need to open ports on a software firewall for example). 另一个选择是让您的应用程序成为HTTP服务器,因此不需要单独的服务器,但这可能属于必须配置HTTP服务器的用户类别(例如,他们可能需要在软件防火墙上打开端口) )。

I would look into how to make a plug-in or a CGI program for your chosen webserver so that your Javascript can access a certain URL on your server and the data returned not come from a real file but just be served by your program handling the web request. 我将研究如何为您选择的Web服务器创建一个插件或CGI程序,以便您的Javascript可以访问您服务器上的某个URL,并且返回的数据不是来自真实文件,而是由您的程序处理网络请求。 (This is possible to do on most web servers. It could be as simple as your C++ program writing to standard console out.) (这可以在大多数Web服务器上执行。它可以像您的C ++程序写入标准控制台一样简单。)

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

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