Skip to main content
. 2022 Apr 8;22(8):2869. doi: 10.3390/s22082869
Algorithm 1 Resource Adaptive Proxy (RAP)
  • /* Define global variables*/

  • BestNode                           ▹ Most powerful resource remote worker

  • EndpointsMap                           ▹ List of endpoints of each endpoint

  • NextEndpoints                           ▹ Endpoints used in the load-balancing

  • ResLists                        ▹ Resource list including CPU, RAM, and latency

  •   1:

    functionResourceAdaptiveProxy

  •   2:

      /* Create separate endpoint list based on name of node*/

  •   3:

      CurrentEndpoints=GetAppInfo(app).endpoints

  •   4:

      if CurrentEndpoints≠LastestEndpoints then

  •   5:

        for endpoints, node in GetAppInfo(app).Item[] do

  •   6:

          EndpointsMap[node].add(endpoints)

  •   7:

        end for

  •   8:

        LastestEndpoints=CurrentEndpoints

  •   9:

      end if

  • 10:

      /* Calculate resources and return the best remote node*/

  • 11:

      MetricServer.Initialize()

  • 12:

      for node in GetAppInfo(app).Item[] do

  • 13:

        AppRes[node].cpu←MetricServer.ResLists.CPU

  • 14:

        AppRes[node].ram←MetricServer.ResLists.RAM

  • 15:

        //Calculate score by summing normalized resource.

  • 16:

        if node≠GetHostname() then

  • 17:

          if AppRes[node].cpu<Threshold&&AppRes[node].ram<Threshold then

  • 18:

            Score[node]=∑r∈ResourcesWr∗(Normalize(AppRes[node])

  • 19:

            if Score[node]>HighestScore then

  • 20:

              HighestScore=Score[node]

  • 21:

              BestNode←node

  • 22:

            end if

  • 23:

          end if

  • 24:

        end if

  • 25:

      end for

  • 26:

    end function

  • 27:

    functionLoadbalancer

  • 28:

      /*Incoming requests are forwarded to NextEndpoint.*/

  • 29:

      if IncomingRequest≠Null then

  • 30:

        LocalNode←GetHostname()

  • 31:

        if AppRes[LocalNode].cpu<Threshold && AppRes[LocalNode].ram<Threshold then

  • 32:

          NextEndpoint←EndpointsMap[LocalNode]

  • 33:

        else

  • 34:

          NextEndpoint←EndpointsMap[BestWorker]

  • 35:

        end if

  • 36:

        //Forward Incoming Request to NextEndpoint

  • 37:

      end if

  • 38:

    end function