Javascript前端与C后端的性能

时间:2022-12-22 06:47:58

I am pulling a JSON file generated on the server, every 5 mins or so (size around 10 KB right now, will get bigger as it goes into production). Once the file is pulled, I have various Javascript Visualization API's, to which I need to plug in the data.

我每隔5分钟左右就会在服务器上生成一个JSON文件(现在大小约为10 KB,在投入生产时会变大)。拉动文件后,我有各种Javascript Visualization API,我需要插入数据。

My backend is in C, and I am using Jquery/Javascript for visualization.

我的后端在C中,我使用Jquery / Javascript进行可视化。

Here are the two approaches that I have: 1. a. Get the entire JSON data ( > 8KB) from the server every 5 mins. b. Parse through the data, using Javascript and extract the required information as per the Javascript API's requirement. (Different visualization api's require different subset of information) c. Display the visualization

以下是我的两种方法:1。每5分钟从服务器获取整个JSON数据(> 8KB)。湾使用Javascript解析数据并根据Javascript API的要求提取所需信息。 (不同的可视化api需要不同的信息子集)c。显示可视化

OR 2. a. Process the data in the back-end itself and extract information as per the Javascript API's and store it in the back-end b. Let each javascript api make independent Ajax calls and get their own data and display it

或2. a。处理后端本身的数据并根据Javascript API提取信息并将其存储在后端b中。让每个javascript api进行独立的Ajax调用并获取自己的数据并显示它

My question is, which of the above two approaches, will yield faster output. Will a backend in C in this case, be faster than a front end in Javascript

我的问题是,上述两种方法中哪一种会产生更快的输出。在这种情况下,C中的后端是否会比Javascript中的前端更快

5 个解决方案

#1


2  

The only answer that can be given is to benchmark both approaches. There are too many variables involved to give a definitive answer.

可以给出的唯一答案是对两种方法进行基准测试。有太多的变量可以给出明确的答案。

The browser being used will make a difference to how long it takes on the client side, so depending on what you need to support, you need to bear this in mind.

正在使用的浏览器会对客户端需要多长时间产生影响,因此根据您需要支持的内容,您需要牢记这一点。

How complicated a data structure that needs to be parsed may make a difference to client side performance.

需要解析的数据结构有多复杂可能会对客户端性能产生影响。

If the data is the same for each user you may swayed toward parsing and caching on the server. If it's different you may want the client to handle this.

如果每个用户的数据相同,您可能会在服务器上进行解析和缓存。如果它不同,您可能希望客户端处理此问题。

#2


0  

I'm unclear with what you are trying to do. Either way, I think that business logic must be contained on the server, and presentation logic (jQuery/javascript or whatever library you are using) must run strictly on a client.

我不清楚你想要做什么。无论哪种方式,我认为业务逻辑必须包含在服务器上,并且表示逻辑(jQuery / javascript或您正在使用的任何库)必须严格地在客户端上运行。

#3


0  

Your second approach would be faster and probably better. Since you said "Let each javascript api... get their own data," it seems like approach 1 would indicate sending a client more than it needs.

你的第二种方法会更快,也可能更好。既然你说“让每个javascript api ...得到他们自己的数据”,似乎方法1表明发送客户端超过它需要。

#4


0  

Depends on how many requests your plugins will make. If you don't have to make any calculation, and everything is done in the first call, and your task is only define where every piece of data should go, then the option 1 is the fastest. Requests are expensive.

取决于您的插件将提出多少请求。如果您不必进行任何计算,并且所有操作都在第一次调用中完成,并且您的任务仅定义了每个数据应该去的位置,则选项1是最快的。请求很昂贵。

On the other hand, if you're going to calculate values in javascript, it depends in how heavy those calculations are. In this case, you'll get a better answer doing a benchmark:

另一方面,如果您要计算javascript中的值,则取决于这些计算的重要程度。在这种情况下,您将获得更好的答案做基准测试:

To clarify, in the first approach your bottle neck will be calculations. In the second, time spent by networking / client's browser speed.

为了澄清,在第一种方法中,你的瓶颈将是计算。第二,网络/客户端浏览器速度所花费的时间。

Consider grouping all results in one JSON result, and passing them to the plugins.

考虑将所有结果分组到一个JSON结果中,并将它们传递给插件。

And consider too, that if you do it on the server, maybe you can use cache to win some processing time (and I say maybe because it depends on what kind of algorithm/data source you're using)

并且考虑一下,如果你在服务器上执行它,也许你可以使用缓存来赢得一些处理时间(我说可能是因为它取决于你正在使用的算法/数据源类型)

Hope it helps, good luck! :-)

希望它有所帮助,祝你好运! :-)

#5


0  

The first thing you should know is that your specific setup will have more impact on the performance of this system so, the only way to know for sure is to benchmark both approaches. That being said, a compiled language like C will almost always be faster than an interpreted language like JavaScript.

您应该知道的第一件事是您的特定设置将对该系统的性能产生更大的影响,因此,唯一可以确定的方法是对两种方法进行基准测试。话虽这么说,像C这样的编译语言几乎总是比像JavaScript这样的解释语言更快。

#1


2  

The only answer that can be given is to benchmark both approaches. There are too many variables involved to give a definitive answer.

可以给出的唯一答案是对两种方法进行基准测试。有太多的变量可以给出明确的答案。

The browser being used will make a difference to how long it takes on the client side, so depending on what you need to support, you need to bear this in mind.

正在使用的浏览器会对客户端需要多长时间产生影响,因此根据您需要支持的内容,您需要牢记这一点。

How complicated a data structure that needs to be parsed may make a difference to client side performance.

需要解析的数据结构有多复杂可能会对客户端性能产生影响。

If the data is the same for each user you may swayed toward parsing and caching on the server. If it's different you may want the client to handle this.

如果每个用户的数据相同,您可能会在服务器上进行解析和缓存。如果它不同,您可能希望客户端处理此问题。

#2


0  

I'm unclear with what you are trying to do. Either way, I think that business logic must be contained on the server, and presentation logic (jQuery/javascript or whatever library you are using) must run strictly on a client.

我不清楚你想要做什么。无论哪种方式,我认为业务逻辑必须包含在服务器上,并且表示逻辑(jQuery / javascript或您正在使用的任何库)必须严格地在客户端上运行。

#3


0  

Your second approach would be faster and probably better. Since you said "Let each javascript api... get their own data," it seems like approach 1 would indicate sending a client more than it needs.

你的第二种方法会更快,也可能更好。既然你说“让每个javascript api ...得到他们自己的数据”,似乎方法1表明发送客户端超过它需要。

#4


0  

Depends on how many requests your plugins will make. If you don't have to make any calculation, and everything is done in the first call, and your task is only define where every piece of data should go, then the option 1 is the fastest. Requests are expensive.

取决于您的插件将提出多少请求。如果您不必进行任何计算,并且所有操作都在第一次调用中完成,并且您的任务仅定义了每个数据应该去的位置,则选项1是最快的。请求很昂贵。

On the other hand, if you're going to calculate values in javascript, it depends in how heavy those calculations are. In this case, you'll get a better answer doing a benchmark:

另一方面,如果您要计算javascript中的值,则取决于这些计算的重要程度。在这种情况下,您将获得更好的答案做基准测试:

To clarify, in the first approach your bottle neck will be calculations. In the second, time spent by networking / client's browser speed.

为了澄清,在第一种方法中,你的瓶颈将是计算。第二,网络/客户端浏览器速度所花费的时间。

Consider grouping all results in one JSON result, and passing them to the plugins.

考虑将所有结果分组到一个JSON结果中,并将它们传递给插件。

And consider too, that if you do it on the server, maybe you can use cache to win some processing time (and I say maybe because it depends on what kind of algorithm/data source you're using)

并且考虑一下,如果你在服务器上执行它,也许你可以使用缓存来赢得一些处理时间(我说可能是因为它取决于你正在使用的算法/数据源类型)

Hope it helps, good luck! :-)

希望它有所帮助,祝你好运! :-)

#5


0  

The first thing you should know is that your specific setup will have more impact on the performance of this system so, the only way to know for sure is to benchmark both approaches. That being said, a compiled language like C will almost always be faster than an interpreted language like JavaScript.

您应该知道的第一件事是您的特定设置将对该系统的性能产生更大的影响,因此,唯一可以确定的方法是对两种方法进行基准测试。话虽这么说,像C这样的编译语言几乎总是比像JavaScript这样的解释语言更快。

相关文章