开发者

Performance of a Javascript Front-End vs C Back-End

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.

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

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 r开发者_如何学Pythonequire different subset of information) c. Display the visualization

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

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


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.


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.


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.


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.

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:

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.

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! :-)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜