コード例 #1
0
ファイル: Herd.java プロジェクト: EvilMcJerkface/SwiftCloud
  public static synchronized void initServer() {
    if (!inited)
      try {
        Networking.rpcBind(PORT, TransportProvider.DEFAULT)
            .toService(
                0,
                new HerdProtoHandler() {
                  public void onReceive(RpcHandle conn, JoinHerdRequest r) {

                    JoinHerdReply reply;
                    synchronized (herds) {
                      if (getHerd(r.dc(), r.herd()).sheep.add(r.sheep())) {
                        lastChange = System.currentTimeMillis();
                      }
                      reply = new JoinHerdReply(age(), herds);
                    }
                    conn.reply(reply);
                  }
                });
        Log.info(IP.localHostname() + " Started Herd server @ " + IP.localHostAddressString());
        inited = true;
      } catch (Exception x) {
        // Log.warning(IP.localHostname() +
        // " Herd is already running???");
      }
  }
コード例 #2
0
ファイル: Herd.java プロジェクト: EvilMcJerkface/SwiftCloud
  public static void joinHerd(
      final String dc, final String herd, final Endpoint endpoint, Endpoint shepardAddress) {
    Thread.dumpStack();

    final Endpoint shepard = Networking.resolve(shepardAddress.getHost(), PORT);
    final RpcEndpoint sock = Networking.rpcConnect(TransportProvider.DEFAULT).toDefaultService();

    Log.info(IP.localHostname() + " Contacting shepard at: " + shepard + " to join: " + herd);
    System.err.println(
        IP.localHostname() + " Contacting shepard at: " + shepard + " to join: " + herd);

    new PeriodicTask(2.0, 1.0) {
      public void run() {
        try {
          sock.send(
              shepard,
              new JoinHerdRequest(dc, herd, endpoint),
              new HerdProtoHandler() {
                public void onReceive(JoinHerdReply r) {
                  herds = r.herds();
                  lastChange = System.currentTimeMillis() - r.age();
                  Log.info(
                      String.format(
                          "Received Herd information: lastChange : [%.1f s] ago, data: %s\n",
                          age() / 1000.0, herds));

                  Threading.synchronizedNotifyAllOn(herds);
                }
              },
              0);
          if (stopProbing) cancel();

        } catch (Exception x) {
          Log.warning("Cannot connect to shepard at: " + shepard + " to join: " + herd);
        }
      }
    };
  }
コード例 #3
0
ファイル: Herd.java プロジェクト: EvilMcJerkface/SwiftCloud
  public static Herd getHerd(String dc, String herd, int minimumAge, boolean stop) {
    Log.info(
        String.format(
            IP.localHostname() + " Waiting up to %s seconds for <%s, %s> membership to settle...\n",
            minimumAge,
            dc,
            herd));

    synchronized (herds) {
      while (age() / 1000 < minimumAge) {
        Threading.synchronizedWaitOn(herds, 100);
      }
      stopProbing = stop;
      return getHerd(dc, herd);
    }
  }
コード例 #4
0
  public void doBenchmark(String[] args) {
    super.init(args);
    // IO.redirect("stdout.txt", "stderr.txt");
    final long startTime = System.currentTimeMillis();

    System.err.println(IP.localHostname() + "/ starting...");

    int concurrentSessions = Args.valueOf(args, "-threads", 1);
    String partitions = Args.valueOf(args, "-partition", "0/1");
    int site = Integer.valueOf(partitions.split("/")[0]);
    int numberOfSites = Integer.valueOf(partitions.split("/")[1]);
    // ASSUMPTION: concurrentSessions is the same at all sites
    int numberOfVirtualSites = numberOfSites * concurrentSessions;

    List<String> candidates = Args.subList(args, "-servers");
    server = ClosestDomain.closest2Domain(candidates, site);
    shepard = Args.valueOf(args, "-shepard", "");

    System.err.println(IP.localHostAddress() + " connecting to: " + server);

    super.populateWorkloadFromConfig();

    SafeLog.printlnComment("");
    SafeLog.printlnComment(String.format("\targs=%s", Arrays.asList(args)));
    SafeLog.printlnComment(String.format("\tsite=%s", site));
    SafeLog.printlnComment(String.format("\tnumberOfSites=%s", numberOfSites));
    SafeLog.printlnComment(String.format("\tthreads=%s", concurrentSessions));
    SafeLog.printlnComment(String.format("\tnumberOfVirtualSites=%s", numberOfVirtualSites));
    SafeLog.printlnComment(String.format("\tSurrogate=%s", server));
    SafeLog.printlnComment(String.format("\tShepard=%s", shepard));

    if (!shepard.isEmpty()) Shepard.sheepJoinHerd(shepard);

    // Kick off all sessions, throughput is limited by
    // concurrentSessions.
    final ExecutorService threadPool =
        Executors.newFixedThreadPool(concurrentSessions, Threading.factory("App"));

    final double sessionOpsPerMs =
        ((double) targetOpsPerSec / (double) concurrentSessions) / 1000.0;
    System.err.println("Spawning session threads.");
    for (int i = 0; i < concurrentSessions; i++) {
      final int sessionId = site * concurrentSessions + i;
      final Workload commands = getWorkloadFromConfig(sessionId, numberOfVirtualSites);
      threadPool.execute(
          new Runnable() {
            public void run() {
              // Randomize startup to avoid clients running all at the
              // same time; causes problems akin to DDOS symptoms.
              Threading.sleep(Sys.rg.nextInt(10000));
              SwiftSocialBenchmark.super.runClientSession(
                  Integer.toString(sessionId), commands, false, sessionOpsPerMs);
            }
          });
    }

    // report client progress every 10 seconds...
    final int PERIOD = 10;
    new PeriodicTask(0.0, 0.0 + PERIOD) {
      private int lastDone;

      public void run() {
        final int recentDone = commandsDone.get();
        final int throughput = (recentDone - lastDone) / PERIOD;
        lastDone = recentDone;
        System.err.printf(
            "Done: %s, throughput %d op/s\n",
            Progress.percentage(recentDone, totalCommands.get()), throughput);
      }
    };

    // Wait for all sessions.
    threadPool.shutdown();
    Threading.awaitTermination(threadPool, Integer.MAX_VALUE);

    System.err.println("Session threads completed.");
    System.err.println(
        "Throughput: "
            + totalCommands.get() * 1000 / (System.currentTimeMillis() - startTime)
            + " txns/s");
    System.exit(0);
  }