ip_vs_sed.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * IPVS: Shortest Expected Delay scheduling module
  3. *
  4. * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Changes:
  12. *
  13. */
  14. /*
  15. * The SED algorithm attempts to minimize each job's expected delay until
  16. * completion. The expected delay that the job will experience is
  17. * (Ci + 1) / Ui if sent to the ith server, in which Ci is the number of
  18. * jobs on the ith server and Ui is the fixed service rate (weight) of
  19. * the ith server. The SED algorithm adopts a greedy policy that each does
  20. * what is in its own best interest, i.e. to join the queue which would
  21. * minimize its expected delay of completion.
  22. *
  23. * See the following paper for more information:
  24. * A. Weinrib and S. Shenker, Greed is not enough: Adaptive load sharing
  25. * in large heterogeneous systems. In Proceedings IEEE INFOCOM'88,
  26. * pages 986-994, 1988.
  27. *
  28. * Thanks must go to Marko Buuri <marko@buuri.name> for talking SED to me.
  29. *
  30. * The difference between SED and WLC is that SED includes the incoming
  31. * job in the cost function (the increment of 1). SED may outperform
  32. * WLC, while scheduling big jobs under larger heterogeneous systems
  33. * (the server weight varies a lot).
  34. *
  35. */
  36. #include <linux/module.h>
  37. #include <linux/kernel.h>
  38. #include <net/ip_vs.h>
  39. static int
  40. ip_vs_sed_init_svc(struct ip_vs_service *svc)
  41. {
  42. return 0;
  43. }
  44. static int
  45. ip_vs_sed_done_svc(struct ip_vs_service *svc)
  46. {
  47. return 0;
  48. }
  49. static int
  50. ip_vs_sed_update_svc(struct ip_vs_service *svc)
  51. {
  52. return 0;
  53. }
  54. static inline unsigned int
  55. ip_vs_sed_dest_overhead(struct ip_vs_dest *dest)
  56. {
  57. /*
  58. * We only use the active connection number in the cost
  59. * calculation here.
  60. */
  61. return atomic_read(&dest->activeconns) + 1;
  62. }
  63. /*
  64. * Weighted Least Connection scheduling
  65. */
  66. static struct ip_vs_dest *
  67. ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
  68. {
  69. struct ip_vs_dest *dest, *least;
  70. unsigned int loh, doh;
  71. IP_VS_DBG(6, "ip_vs_sed_schedule(): Scheduling...\n");
  72. /*
  73. * We calculate the load of each dest server as follows:
  74. * (server expected overhead) / dest->weight
  75. *
  76. * Remember -- no floats in kernel mode!!!
  77. * The comparison of h1*w2 > h2*w1 is equivalent to that of
  78. * h1/w1 > h2/w2
  79. * if every weight is larger than zero.
  80. *
  81. * The server with weight=0 is quiesced and will not receive any
  82. * new connections.
  83. */
  84. list_for_each_entry(dest, &svc->destinations, n_list) {
  85. if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
  86. atomic_read(&dest->weight) > 0) {
  87. least = dest;
  88. loh = ip_vs_sed_dest_overhead(least);
  89. goto nextstage;
  90. }
  91. }
  92. return NULL;
  93. /*
  94. * Find the destination with the least load.
  95. */
  96. nextstage:
  97. list_for_each_entry_continue(dest, &svc->destinations, n_list) {
  98. if (dest->flags & IP_VS_DEST_F_OVERLOAD)
  99. continue;
  100. doh = ip_vs_sed_dest_overhead(dest);
  101. if (loh * atomic_read(&dest->weight) >
  102. doh * atomic_read(&least->weight)) {
  103. least = dest;
  104. loh = doh;
  105. }
  106. }
  107. IP_VS_DBG(6, "SED: server %u.%u.%u.%u:%u "
  108. "activeconns %d refcnt %d weight %d overhead %d\n",
  109. NIPQUAD(least->addr), ntohs(least->port),
  110. atomic_read(&least->activeconns),
  111. atomic_read(&least->refcnt),
  112. atomic_read(&least->weight), loh);
  113. return least;
  114. }
  115. static struct ip_vs_scheduler ip_vs_sed_scheduler =
  116. {
  117. .name = "sed",
  118. .refcnt = ATOMIC_INIT(0),
  119. .module = THIS_MODULE,
  120. .init_service = ip_vs_sed_init_svc,
  121. .done_service = ip_vs_sed_done_svc,
  122. .update_service = ip_vs_sed_update_svc,
  123. .schedule = ip_vs_sed_schedule,
  124. };
  125. static int __init ip_vs_sed_init(void)
  126. {
  127. INIT_LIST_HEAD(&ip_vs_sed_scheduler.n_list);
  128. return register_ip_vs_scheduler(&ip_vs_sed_scheduler);
  129. }
  130. static void __exit ip_vs_sed_cleanup(void)
  131. {
  132. unregister_ip_vs_scheduler(&ip_vs_sed_scheduler);
  133. }
  134. module_init(ip_vs_sed_init);
  135. module_exit(ip_vs_sed_cleanup);
  136. MODULE_LICENSE("GPL");