I am designing and implementing property management system and I have dashboard which contains rooms' bookings for specified date intervals.
我正在设计和实施物业管理系统,我有仪表板,其中包含指定日期间隔的房间预订。
What am I asking, is related to performance [loading rooms' information]. Currently, I have
我要问的是,与性能[装载室信息]有关。目前,我有
for (var r = 0; r < rooms.length; r++)
{
$.ajax({
type: 'POST',
url: '/dashboard/getAllOrders.php',
data: 'room_id=' + encodeURIComponent(rooms[r].id),
complete: function (e, xhr, settings) {
if (e.status === 200)
{
var orders = $.parseJSON(e.responseText);
for (var i = 0; i < orders.length; i++)
{
drawOrder(orders[i]);
}
}
}
});
}
But, I can also write it as:
但是,我也可以把它写成:
var room_ids = [];
for (var r = 0; r < rooms.length; r++)
{
room_ids.push(rooms[r].id);
}
$.ajax({
type: 'POST',
url: '/dashboard/getAllRoomsOrders.php',
data: { 'room_ids' : room_ids },
complete: function(event, request, settings)
{
if (event.status === 200)
{
var orders = $.parseJSON(event.responseText);
for (var i = 0; i < orders.length; i++)
{
drawOrder(orders[i]);
}
}
}
});
Could you recommend me which option do I need to to stick with and provide arguments which will prove why one option is better, than other, from performance point of view?
您能否从性能的角度推荐我需要哪个选项并提供参数来证明为什么一个选项比其他选项更好?
If not, could you recommend the best benchmarking practices for client-server applications?
如果没有,您能为客户端 - 服务器应用程序推荐最佳基准测试实践吗?
1 个解决方案
#1
0
You may see little to no difference for very small amounts of data, however, as the number of roomId's increases, you'll begin to see the first approach taking longer than the second mostly due to bandwidth.
对于非常少量的数据,您可能会发现几乎没有差别,但是,随着roomId的数量增加,您将开始看到第一种方法比第二种方法花费的时间更长。
By combining all of these requests into a single request, you are reducing the amount of network traffic between the client and the webserver and the webserver and the db server because in both cases combining the request removes the need to repeatedly send header data and sql queries and instead sends them once thus reducing network traffic and db lookups.
通过将所有这些请求组合到单个请求中,您减少了客户端与Web服务器以及Web服务器和数据库服务器之间的网络流量,因为在两种情况下组合请求都不需要重复发送头数据和SQL查询而是发送一次,从而减少网络流量和数据库查找。
#1
0
You may see little to no difference for very small amounts of data, however, as the number of roomId's increases, you'll begin to see the first approach taking longer than the second mostly due to bandwidth.
对于非常少量的数据,您可能会发现几乎没有差别,但是,随着roomId的数量增加,您将开始看到第一种方法比第二种方法花费的时间更长。
By combining all of these requests into a single request, you are reducing the amount of network traffic between the client and the webserver and the webserver and the db server because in both cases combining the request removes the need to repeatedly send header data and sql queries and instead sends them once thus reducing network traffic and db lookups.
通过将所有这些请求组合到单个请求中,您减少了客户端与Web服务器以及Web服务器和数据库服务器之间的网络流量,因为在两种情况下组合请求都不需要重复发送头数据和SQL查询而是发送一次,从而减少网络流量和数据库查找。