[vlma-devel] commit: Simplify load balancing. (Adrien Grand )

git version control git at videolan.org
Tue Nov 11 12:29:06 CET 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Tue Nov 11 12:22:22 2008 +0100| [801910ca7e45111ae0fe58940ac69a89c4e026fb] | committer: Adrien Grand 

Simplify load balancing.

Don't try to split orders.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=801910ca7e45111ae0fe58940ac69a89c4e026fb
---

 .../main/java/org/videolan/vlma/OrderGiver.java    |   47 +++++--------------
 .../java/org/videolan/vlma/OrderGiverTest.java     |   48 --------------------
 2 files changed, 12 insertions(+), 83 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java b/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
index 5a65d19..19ab5cb 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
@@ -238,10 +238,11 @@ public class OrderGiver {
             }
         }
         // Now that we have a configuration that optimizes the number of
-        // broadcasted channels, try to do some load balancing
+        // broadcasted channels, try to do some basic load balancing
         List<Server> servers = new ArrayList<Server>();
         servers.addAll(load.keySet());
         while(adapterIt.hasNext()) {
+            boolean orderFound = false;
             Collections.sort(servers,
                     new Comparator<Server>() {
                         public int compare(Server server1, Server server2) {
@@ -263,43 +264,19 @@ public class OrderGiver {
                             && order.getMedias().size() > 1) {
                         /* We found a server with a high load which has to
                          * broadcast medias that could be streamed by an
-                         * adapter which is still free, so divide the
-                         * mediagroup in two smaller groups */
-                        int transferableLoad = (load.get(order.getAdapter().getServer()) - load.get(adapter.getServer()))/2;
-                        int orderLoad = order.getMedias().getLoad();
-
-                        // Divide the order in two smallers ones
-                        MediaGroup g1 = new MediaGroup();
-                        MediaGroup g2 = new MediaGroup();
-                        int i = g1.getLoad();
-                        for(Media media : order.getMedias()) {
-                            if(i++ <= transferableLoad) {
-                                g1.add(media);
-                            } else {
-                                g2.add(media);
-                            }
-                        }
-                        if(g1.size() == 0) {
-                            // All orders are on the new adapter
-                            load.put(adapter.getServer(),
-                                    load.get(adapter.getServer()) + orderLoad);
-                            load.put(order.getAdapter().getServer(),
-                                    load.get(order.getAdapter().getServer()) - orderLoad);
-                            order.setAdapter(adapter);
-                        } else if(g2.size() != 0) {
-                            load.put(order.getAdapter().getServer(),
-                                    load.get(order.getAdapter().getServer()) - orderLoad + g1.getLoad());
-                            order.setMedias(g1);
-                            load.put(adapter.getServer(),
-                                    load.get(adapter.getServer()) + g2.getLoad());
-                            Order order2 = new Order(adapter, g2);
-                            orders.add(order2);
-                        }
-                        // If g2.size() == 0, nothing to do
+                         * adapter which is still free and whose server
+                         * has a lower load, so change the adapter in charge
+                         * of the order */
+                        int l = order.getMedias().getLoad();
+                        load.put(order.getAdapter().getServer(), load.get(order.getAdapter().getServer()) - l);
+                        order.setAdapter(adapter);
+                        load.put(adapter.getServer(), load.get(adapter.getServer()) + l);
+                        orderFound = true;
                         break;
                     }
                 }
-                break;
+                if(orderFound)
+                    break;
             }
         }
     }
diff --git a/vlma-core/src/test/java/org/videolan/vlma/OrderGiverTest.java b/vlma-core/src/test/java/org/videolan/vlma/OrderGiverTest.java
index 760e1fd..3c921cf 100644
--- a/vlma-core/src/test/java/org/videolan/vlma/OrderGiverTest.java
+++ b/vlma-core/src/test/java/org/videolan/vlma/OrderGiverTest.java
@@ -153,52 +153,4 @@ public class OrderGiverTest extends TestCase {
         assertTrue(0 < orderGiver.computeOrders(orderGiver.partitionMedias(medias, adapters), adapters).size());
     }
 
-    public void testLoadBalancing() throws Exception {
-        Server s1 = new Server();
-        s1.setName("server1");
-        s1.setIp(InetAddress.getByName("192.168.0.1"));
-        Server s2 = new Server();
-        s2.setName("server2");
-        s1.setIp(InetAddress.getByName("192.168.0.2"));
-        List<Server> servers = new ArrayList<Server>();
-        servers.add(s1);
-        servers.add(s2);
-
-        Adapter a1 = new DVBTAdapter();
-        a1.setName("a1");
-        Adapter a2 = new DVBTAdapter();
-        a2.setName("a2");
-        a1.setServer(s1);
-        s1.addAdapter(a1);
-        a2.setServer(s2);
-        s2.addAdapter(a2);
-
-        List<Media> medias = new ArrayList<Media>();
-        DTTChannel m1 = new DTTChannel();
-        m1.setName("m1");
-        m1.setProgram(new Program());
-        m1.setFrequency(42);
-        m1.setSid(1024);
-        medias.add(m1);
-        DTTChannel m2 = new DTTChannel();
-        m2.setName("m2");
-        m2.setProgram(new Program());
-        // same frequency so that they will be in the same group
-        m2.setFrequency(42);
-        m2.setSid(1025);
-        medias.add(m2);
-
-        Map<String, List<Adapter>> adapters = orderGiver.partitionAdapters(servers);
-        Map<String, List<MediaGroup> > groups = orderGiver.partitionMedias(medias, adapters);
-        // Both medias are in the same group
-        assertEquals(1, groups.values().size());
-        Set<Order> orders = orderGiver.computeOrders(groups, adapters);
-        // But there are 2 orders because of load balancing
-        assertEquals(2, orders.size());
-        // And each order has at least one media
-        for(Order order : orders) {
-            assertTrue(1 <= order.getMedias().size());
-        }
-    }
-
 }



More information about the vlma-devel mailing list