Example #1
0
        /// <exception cref="System.IO.IOException"/>
        public TeraScheduler(string splitFilename, string nodeFilename)
        {
            slotsPerHost = 4;
            // get the hosts
            IDictionary <string, TeraScheduler.Host> hostIds = new Dictionary <string, TeraScheduler.Host
                                                                               >();

            foreach (string hostName in ReadFile(nodeFilename))
            {
                TeraScheduler.Host host = new TeraScheduler.Host(hostName);
                hosts.AddItem(host);
                hostIds[hostName] = host;
            }
            // read the blocks
            IList <string> splitLines = ReadFile(splitFilename);

            splits          = new TeraScheduler.Split[splitLines.Count];
            remainingSplits = 0;
            foreach (string line in splitLines)
            {
                StringTokenizer     itr      = new StringTokenizer(line);
                TeraScheduler.Split newSplit = new TeraScheduler.Split(itr.NextToken());
                splits[remainingSplits++] = newSplit;
                while (itr.HasMoreTokens())
                {
                    TeraScheduler.Host host = hostIds[itr.NextToken()];
                    newSplit.locations.AddItem(host);
                    host.splits.AddItem(newSplit);
                }
            }
        }
Example #2
0
        /// <exception cref="System.IO.IOException"/>
        public TeraScheduler(FileSplit[] realSplits, Configuration conf)
        {
            this.realSplits   = realSplits;
            this.slotsPerHost = conf.GetInt(TTConfig.TtMapSlots, 4);
            IDictionary <string, TeraScheduler.Host> hostTable = new Dictionary <string, TeraScheduler.Host
                                                                                 >();

            splits = new TeraScheduler.Split[realSplits.Length];
            foreach (FileSplit realSplit in realSplits)
            {
                TeraScheduler.Split split = new TeraScheduler.Split(realSplit.GetPath().ToString(
                                                                        ));
                splits[remainingSplits++] = split;
                foreach (string hostname in realSplit.GetLocations())
                {
                    TeraScheduler.Host host = hostTable[hostname];
                    if (host == null)
                    {
                        host = new TeraScheduler.Host(hostname);
                        hostTable[hostname] = host;
                        hosts.AddItem(host);
                    }
                    host.splits.AddItem(split);
                    split.locations.AddItem(host);
                }
            }
        }
Example #3
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual void Solve()
 {
     TeraScheduler.Host host = PickBestHost();
     while (host != null)
     {
         PickBestSplits(host);
         host = PickBestHost();
     }
 }
Example #4
0
        internal virtual void PickBestSplits(TeraScheduler.Host host)
        {
            int tasksToPick = Math.Min(slotsPerHost, (int)Math.Ceil((double)remainingSplits /
                                                                    hosts.Count));

            TeraScheduler.Split[] best = new TeraScheduler.Split[tasksToPick];
            foreach (TeraScheduler.Split cur in host.splits)
            {
                Log.Debug("  examine: " + cur.filename + " " + cur.locations.Count);
                int i = 0;
                while (i < tasksToPick && best[i] != null && best[i].locations.Count <= cur.locations
                       .Count)
                {
                    i += 1;
                }
                if (i < tasksToPick)
                {
                    for (int j = tasksToPick - 1; j > i; --j)
                    {
                        best[j] = best[j - 1];
                    }
                    best[i] = cur;
                }
            }
            // for the chosen blocks, remove them from the other locations
            for (int i_1 = 0; i_1 < tasksToPick; ++i_1)
            {
                if (best[i_1] != null)
                {
                    Log.Debug(" best: " + best[i_1].filename);
                    foreach (TeraScheduler.Host other in best[i_1].locations)
                    {
                        other.splits.Remove(best[i_1]);
                    }
                    best[i_1].locations.Clear();
                    best[i_1].locations.AddItem(host);
                    best[i_1].isAssigned = true;
                    remainingSplits     -= 1;
                }
            }
            // for the non-chosen blocks, remove this host
            foreach (TeraScheduler.Split cur_1 in host.splits)
            {
                if (!cur_1.isAssigned)
                {
                    cur_1.locations.Remove(host);
                }
            }
        }
Example #5
0
        internal virtual TeraScheduler.Host PickBestHost()
        {
            TeraScheduler.Host result = null;
            int splits = int.MaxValue;

            foreach (TeraScheduler.Host host in hosts)
            {
                if (host.splits.Count < splits)
                {
                    result = host;
                    splits = host.splits.Count;
                }
            }
            if (result != null)
            {
                hosts.Remove(result);
                Log.Debug("picking " + result);
            }
            return(result);
        }