示例#1
0
  /**
   * @param args
   * @throws JSONException
   * @throws ExecutionException
   * @throws InterruptedException
   */
  public static void main(String[] args)
      throws JSONException, InterruptedException, ExecutionException {
    int numProcess = Integer.parseInt(args[0]);
    int numThread = Integer.parseInt(args[1]);
    boolean blocking = Boolean.parseBoolean(args[2]);
    if (numProcess <= 0) {
      System.out.println("Number of clients must be larger than 0.");
      System.exit(0);
    }

    final ThreadPoolExecutor executor;

    executor =
        new ThreadPoolExecutor(
            numProcess * numThread,
            numProcess * numThread,
            0,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
    executor.prestartAllCoreThreads();

    String guid = "4B48F507395639FD806459281C3C09BCBB16FDFF";
    String field = "someField";
    String noop_code = "";
    try {
      noop_code = new String(Files.readAllBytes(Paths.get("./scripts/activeCode/noop.js")));
    } catch (IOException e) {
      e.printStackTrace();
    }
    ValuesMap value = new ValuesMap();
    value.put(field, "someValue");

    // initialize a handler
    ActiveHandler handler = new ActiveHandler("", null, numProcess, numThread, blocking);
    ArrayList<Future<JSONObject>> tasks = new ArrayList<Future<JSONObject>>();

    int n = 1000000;

    long t1 = System.currentTimeMillis();

    for (int i = 0; i < n; i++) {
      tasks.add(
          executor.submit(
              new ActiveTask(clientPool[i % numProcess], guid, field, noop_code, value, 0)));
    }
    for (Future<JSONObject> task : tasks) {
      task.get();
    }

    long elapsed = System.currentTimeMillis() - t1;
    System.out.println(
        "It takes "
            + elapsed
            + "ms, and the average latency for each operation is "
            + (elapsed * 1000.0 / n)
            + "us");
    System.out.println("The throughput is " + Util.df(n * 1000.0 / elapsed) + "reqs/sec");
    handler.shutdown();

    System.out.println(DelayProfiler.getStats());
    System.exit(0);
  }
示例#2
0
  @Override
  public HashMap<ColumnField, Object> lookupSomeFields(
      String collection,
      String name,
      ColumnField nameField,
      ColumnField valuesMapField,
      ArrayList<ColumnField> valuesMapKeys)
      throws RecordNotFoundException, FailedDBOperationException {

    JSONObject record = lookupEntireRecord(collection, name);
    //    DatabaseConfig.getLogger().log(Level.FINE, "Full record " + record.toString());
    HashMap<ColumnField, Object> hashMap = new HashMap<>();
    hashMap.put(nameField, name);
    if (valuesMapField != null && valuesMapKeys != null) {
      try {
        JSONObject readValuesMap = record.getJSONObject(valuesMapField.getName());
        //        DatabaseConfig.getLogger().log(Level.FINE, "Read valuesMap " +
        // readValuesMap.toString());
        ValuesMap valuesMapOut = new ValuesMap();
        for (int i = 0; i < valuesMapKeys.size(); i++) {
          String userKey = valuesMapKeys.get(i).getName();
          if (JSONDotNotation.containsFieldDotNotation(userKey, readValuesMap) == false) {
            //            DatabaseConfig.getLogger().fine("valuesMap doesn't contain " + userKey);
            continue;
          }
          try {
            switch (valuesMapKeys.get(i).type()) {
              case USER_JSON:
                Object value = JSONDotNotation.getWithDotNotation(userKey, readValuesMap);
                DatabaseConfig.getLogger()
                    .log(Level.FINE, "Object is {0}", new Object[] {value.toString()});
                valuesMapOut.put(userKey, value);
                break;
              case LIST_STRING:
                valuesMapOut.putAsArray(
                    userKey,
                    JSONUtils.JSONArrayToResultValue(
                        new JSONArray(
                            JSONDotNotation.getWithDotNotation(userKey, readValuesMap)
                                .toString())));
                break;
              default:
                DatabaseConfig.getLogger()
                    .log(
                        Level.SEVERE,
                        "ERROR: Error: User keys field {0} is not a known type:{1}",
                        new Object[] {userKey, valuesMapKeys.get(i).type()});
                break;
            }
          } catch (JSONException e) {
            DatabaseConfig.getLogger().log(Level.SEVERE, "Error parsing json: {0}", e.getMessage());
          }
        }
        hashMap.put(valuesMapField, valuesMapOut);
      } catch (JSONException e) {
        DatabaseConfig.getLogger()
            .log(Level.SEVERE, "Problem getting values map: {0}", e.getMessage());
      }
    }
    return hashMap;
  }