Mercurial > hg > freeDiameter
comparison extensions/rt_load_balance/rt_load_balance.c @ 1273:e831cabceab0
Switch to logarithmic scaling.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Fri, 23 May 2014 16:08:04 +0200 |
parents | f6ad5596aac7 |
children | 38e4a7c318ac |
comparison
equal
deleted
inserted
replaced
1272:34265c9c1e94 | 1273:e831cabceab0 |
---|---|
1 /********************************************************************************************************* | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | 2 * Software License Agreement (BSD License) * |
3 * Author: Thomas Klausner <tk@giga.or.at> * | 3 * Author: Thomas Klausner <tk@giga.or.at> * |
4 * * | 4 * * |
5 * Copyright (c) 2013, Thomas Klausner * | 5 * Copyright (c) 2013, 2014 Thomas Klausner * |
6 * All rights reserved. * | 6 * All rights reserved. * |
7 * * | 7 * * |
8 * Written under contract by nfotex IT GmbH, http://nfotex.com/ * | 8 * Written under contract by nfotex IT GmbH, http://nfotex.com/ * |
9 * * | 9 * * |
10 * Redistribution and use of this software in source and binary forms, with or without modification, are * | 10 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
56 long to_receive, to_send, load; | 56 long to_receive, to_send, load; |
57 int score; | 57 int score; |
58 CHECK_FCT(fd_peer_getbyid(cand->diamid, cand->diamidlen, 0, &peer)); | 58 CHECK_FCT(fd_peer_getbyid(cand->diamid, cand->diamidlen, 0, &peer)); |
59 CHECK_FCT(fd_peer_get_load_pending(peer, &to_receive, &to_send)); | 59 CHECK_FCT(fd_peer_get_load_pending(peer, &to_receive, &to_send)); |
60 load = to_receive + to_send; | 60 load = to_receive + to_send; |
61 score = cand->score; | 61 /* other routing mechanisms need to add to the |
62 if ((cand->score > 0) && (load >= cand->score)) | 62 * appropriate entries so their base value is high |
63 cand->score = 1; | 63 * enough that they are considered */ |
64 else | 64 |
65 cand->score -= load; | 65 /* logarithmic scaling */ |
66 int load_log = 0; | |
67 while (load > 0) { | |
68 load_log++; | |
69 load /= 2; | |
70 } | |
71 cand->score -= load_log; | |
66 TRACE_DEBUG(FULL, "evaluated peer `%.*s', score was %d, now %d", (int)cand->diamidlen, cand->diamid, score, cand->score); | 72 TRACE_DEBUG(FULL, "evaluated peer `%.*s', score was %d, now %d", (int)cand->diamidlen, cand->diamid, score, cand->score); |
67 } | 73 } |
68 | 74 |
69 return 0; | 75 return 0; |
70 } | 76 } |