Ignore:
Timestamp:
May 6, 2011 9:51:57 AM (13 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanoscale/server.c

    r1380 r2238  
    1414#include <getopt.h>
    1515#include <errno.h>
     16#include <tcl.h>
    1617
    1718// The initial request load for a new renderer.
     
    7576            _x > _y ? _x : _y; })
    7677
    77 #ifdef notdef
    78 static int
    79 find_best_host(void)
    80 {
    81     int h;
    82     float best = load;
    83     int index = -1;
    84     //printf("My load is %f\n", best);
    85     for(h=0; h<sizeof(host_array)/sizeof(host_array[0]); h++) {
    86         if (host_array[h].in_addr.s_addr == 0)
    87             continue;
    88         //printf("%d I think load for %s is %f   ", h,
    89         //       inet_ntoa(host_array[h].in_addr), host_array[h].load);
    90         if (host_array[h].children <= children) {
    91             if (host_array[h].load < best) {
    92                 //if ((random() % 100) < 75) {
    93                 index = h;
    94                 best = host_array[h].load;
    95                 //}
    96                 //printf(" Better\n");
    97             } else {
    98                 //printf(" Worse\n");
    99             }
    100         }
    101     }
    102 
    103     //printf("I choose %d\n", index);
    104     return index;
    105 }
    106 #endif
    107 
    108 static void
    109 broadcast_load(void)
    110 {
    111     int msg[2];
    112     msg[0] = htonl(load);
    113     msg[1] = htonl(children);
    114     int status;
    115     status = sendto(send_fd, &msg, sizeof(msg), 0, (struct sockaddr *)&send_addr,
    116                     sizeof(send_addr));
    117     if (status < 0) {
    118         perror("sendto");
    119     }
    120 }
    12178
    12279static void
     
    14097           children, memory_in_use, load);
    14198
    142 #ifdef notdef
    143     broadcast_load();
    144 #endif
    14599}
    146100
     
    158112            return;
    159113        }
    160     }
    161 }
    162 
    163 static void
    164 update_load_average(void)
    165 {
    166     static unsigned int counter;
    167 
    168     load = load / LOAD_DROP_OFF;
    169     float newload = 0.0;
    170     int c;
    171     for(c=0; c < sizeof(child_array)/sizeof(child_array[0]); c++) {
    172         if (child_array[c].pipefd != 0) {
    173             newload += child_array[c].requests * child_array[c].memory;
    174             child_array[c].requests = 0;
    175         }
    176     }
    177     load = load + newload;
    178 
    179     if ((counter++ % BROADCAST_INTERVAL) == 0) {
    180         broadcast_load();
    181114    }
    182115}
     
    291224        server_command[0][0]=='\0') {
    292225        int i;
    293         fprintf(stderr, "nservices=%d, recv_port=%d, server_command[0]=%s\n", nservices, recv_port, server_command[0]);
    294226        for (i = 0; i < argc; i++) {
    295227            fprintf(stderr, "argv[%d]=(%s)\n", i, argv[i]);
     
    399331    // We're ready to go.  Before going into the main loop,
    400332    // broadcast a load announcement to other machines.
    401 #ifdef notdef
    402     broadcast_load();
    403 #endif
    404333    int maxfd = send_fd;
    405334    FD_ZERO(&saved_rfds);
     
    428357        if (status <= 0) {
    429358            if (sigalarm_set) {
    430                 update_load_average();
    431359                sigalarm_set = 0;
    432360            }
    433361            continue;
    434362        }
    435      
    436363     
    437364        int accepted = 0;
     
    537464                int newmemory = ntohl(msg);
    538465             
    539 #ifdef notdef
    540                 // Find the best host to create a new child on.
    541                 int index = find_best_host();
    542              
    543                 // Only redirect if another host's load is significantly less
    544                 // than our own...
    545                 if (index != -1 &&
    546                     (host_array[index].load < (LOAD_REDIRECT_FACTOR * load))) {
    547                  
    548                     // If we're redirecting to another machine, give that
    549                     // machine an extra boost in our copy of the load
    550                     // statistics.  This will keep us from sending the very
    551                     // next job to it.  Eventually, the other machine will
    552                     // broadcast its real load and we can make an informed
    553                     // decision as to who redirect to again.
    554                     host_array[index].load += newmemory * INITIAL_LOAD;
    555                  
    556                     // Redirect to another machine.
    557                     printf("Redirecting to %s\n",
    558                            inet_ntoa(host_array[index].in_addr));
    559                     write(i, &host_array[index].in_addr.s_addr, 4);
    560                     FD_CLR(i, &saved_rfds);
    561                     clear_service_fd(i);
    562                     close(i);
    563                     continue;
    564                 }
    565 #endif
    566466                memory_in_use += newmemory;
    567467                load += 2*INITIAL_LOAD;
    568 #ifdef notdef
    569                 broadcast_load();
    570 #endif
    571468                printf("Accepted new job with memory %d\n", newmemory);
    572469                //printf("My load is now %f\n", load);
     
    654551                 
    655552                    children++;
    656                     broadcast_load();
    657553                }
    658554             
Note: See TracChangeset for help on using the changeset viewer.