开发者

Ajax.net - Improve Page Load Time

here's my problem. I'm developing a website that will allow users to book hotels all around the wor开发者_开发问答ld, just like booking.com, expedia.com, etc.

When the user searches for hotels in a certain city, I connect through Web Services with different providers, and then show the results. In almost every provider this means:

1) Calling a method in WS that returns available hotels in the city for selected dates. For each of these hotels:

  • 2) Read from a very large XML files (usually more than 1) to obtain static information like address, phone, fax, description, services, etc.
  • 3) Call a second method in WS to get available rooms information.
  • 4) Show result

The problem I'm having has to do with page load time, which is a key factor in these Websites.

The first call to the WS (point 1), it's something necessary in which there's not much I can do, so I have to accept this time. The other two points are also necessary, but my intention is to improve the user experience by showing hotels as they load.

Let's say you are looking for hotels in Buenos Aires. You enter "Buenos Aires" as your destination, and hit the "Buscar" button. As you may notice, a loading message is shown until the following page has been completely loaded. Instead of waiting for all hotels to load, what I would like to do, which I think will improve user's experience is:

  1. When user hits "Buscar" button, immeadiately send user to HotelList page
  2. Show each hotel as their information is obtained, and a message on the top saying something like "Loading 1 of XXX hotels"... "Loading 2 of XXX hotels" ...

I've been looking for ajax examples that would describe how to achieve this, but haven't found any clear articles. I would really much appretiate is someone could point me out in the right direction.

Thanks!

---------------------------------------------------------------------------

Tried using multi-threading but results aren't displayed. I'm showing the results using a Literal Control. Here's a piece of the code:

HotelList.aspx

<asp:Literal ID="HotelesResultadoBusqueda" runat="server"></asp:Literal>

HotelList.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    ...
    ...
    ThreadStart job = new ThreadStart(CargarHoteles);
    Thread thread = new Thread(job);
    thread.Start();
}

private void CargarHoteles()
{
    // Load Hotels
    ArrayList hotels = WebService......
    foreach(Hotel hotel in hotels)
    {.....}
    ....
    this.HotelesResultadoBusqueda.Text = "...";
}


Re "as they arrive", the simplest thing there is to build a (thread-safe) queue of pending items at the back-end, I.e. New results go in the queue - and have your JSON query poll every few seconds for new data in the queue (for that session).

Re performance; just profile it and attack the bits that the profile shows is hurting. Pre-loading the XML into some indexed structure (maybe even a database) would be my main guess...


Here is my idea, the goal is to cache the results of your CargarHoteles() hotels function. Because you are caching it you can have a background process do the work while the user interface responds quickly.

When the client first asks for information about a set of parameters the service return a unique id for that set of parameters (it looks to see if it is already in the cache and returns that if it exists). When the client gets the unique id it starts asking the server for some results -- if they are already in the cache they come back right away -- or a subset comes back with an indication of how much of the search is done.

On the server side you have a worker process (or processes -- this solution allows you to toss more machines/process at the task if there is a good way to do so, for example a task for every xml file.) These workers are solving the problem and putting the results in the cache, when they are done they flag that cache item as finished. The next time the client requests more information it learns it has all the results.

Note that this design is compatible with Marc's suggestion, that is the queue he talks about is the results which are being built as an entry in the cache.

One of the nice features of this solution is if there is a lot of interest in one location (everyone is going to the Olympics!) your website gets faster.

I hope this is clear. Post questions if it is not and I will try and explain more.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜