A page tour Erlang service-side broadcast algorithm is very inefficient, it should be considered a bug.

Source: Internet
Author: User

Accidentally get a copy of the code on the Erlang Web page Server
I have to say it is very elegant, the document is very good, but I see his scene management in the broadcast algorithm, have to say that the writing is very beautiful, but very low efficiency.

Each time the global traversal of all online players in a scene of the toy ID, such an algorithm, I do not know how much a service can prop up the number of people, optimization, scene services management in his service players, npc,mon, efficiency will increase several times, but the code will be a little more complex, not his elegant writing!!



Percent  gain to broadcast the range of users idget_broadcast_id (Q, X0, Y0),    AllUser = Ets:match (? Ets_online, #ets_online {id = ' $ ', x = ' $ ', y= ' $ ', scene = Q, _= ' _ '}), <span style= "color: #ff6666;" > Percent This code efficiency will be very poor, and to execute more times </span>    XY2 = Lib_scene:get_xy (X0, Y0),    get_broadcast_id_loop (AllUser, XY2 , []). Get_broadcast_id_loop ([], _xy2, D),    d;get_broadcast_id_loop ([ID, X, y]|  T], XY2, D)    xy = Lib_scene:get_xy (X, Y),    if        xy = = XY2 OrElse XY = = XY2 + 1 OrElse xy = = xy2-1 OrElse xy = = Xy2-8 OrElse xy = = XY2 +8 OrElse xy = xy2-9 OrElse xy = XY2 +9 orelse xy = xy2-7 OrElse  xy = = Xy2+7->
   get_broadcast_id_loop (T, XY2, D++[id]);        True->            Get_broadcast_id_loop (T, XY2, D)    end.


A page tour Erlang service-side broadcast algorithm is very inefficient, it should be considered a bug.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.