Should data sorting be done on the client or on the server?

前端 未结 4 577
刺人心
刺人心 2021-02-05 09:39

I get data from a server and want to display it using GWT on the client.

GWT is not the problem here, you can replace GWT by Ajax calls or you can transpose it to a real

相关标签:
4条回答
  • 2021-02-05 10:08

    One should be careful of an all-inclusive statement that it is ALWAYS faster to sort on the server than on the client. I had a case where I was returning several thousand records sorted by the concatenation of the last name and first name. Neither one of these fields were indexed and I had no control over this. As we know, sorting concatenated strings is not something the database does well intrinsically. It looks numbers and/or indexed fields. Sorting on the client in this case ended up being faster. If I had the control over the database, I would have placed a function index in Oracle on these two fields.

    The moral of the story is to ASSUME NOTHING and profile your application to find out what works best for your scenario.

    0 讨论(0)
  • 2021-02-05 10:20

    It depends... :)

    1. How much data is to be sorted? How fast? "fast as possible" ok... what's the slowest you can accept? Can the client handle this? What about the server? What other responsibilities do these elements have and does this create conflict?
    2. How reliably must the data be sorted? For example, if the data were not sorted sometimes would this be OK?
    3. How are the responsibilities allocated to the elements in your architecture? For that matter, what are the elements? Do you have a database? What about a business tier? The world could be more complex than just "client vs. server"
    4. How will the data be used? Will multiple sorts need to be performed? For example, A->Z and Z->A?
    5. Is the cost of transferring data between the client and server reasonable? Are there other ways to make it reasonable?

    Architecturally speaking, to answer this question you need to decide on the desired properties in your system and evaluate the trade-offs among various design alternatives. Without knowing more about your system it is difficult to offer advice beyond this.

    0 讨论(0)
  • 2021-02-05 10:28

    Each approach has its pros and cons:

    • If you need pagination, and don't want to download the entire data to the client, then you must perform the sorting on the server (otherwise the client can only sort the rows it currently has, which will lead to wrong results, if you re-sort by a different column)
    • Sorting on the server is faster (as in: you can sort more rows/second), but if you have to serve 10000 clients at once, this may easily invert.
    • When sorting on the client, you can re-sort without downloading the data again.
    0 讨论(0)
  • 2021-02-05 10:29

    Ideally, the sort should be done on the server because:-

    1. It is best to assume that your client will be having low resources. For example, some people will launch the GWT app from a desktop but another may launch the GWT app from a iPad/phone which is having less CPU/RAM

    2. There are standard ways to do sorting on the server side, for example, by using SQL ORDER BY clause but you may have to implement your own routine/method to do the sorting on the client side.

    0 讨论(0)
提交回复
热议问题