You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/12/10 13:56:11 UTC

[GitHub] [incubator-ratis] szetszwo commented on a change in pull request #347: RATIS-1229. FileStore client generate files in parallel

szetszwo commented on a change in pull request #347:
URL: https://github.com/apache/incubator-ratis/pull/347#discussion_r540179397



##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Client.java
##########
@@ -153,6 +199,7 @@ protected void writeFile(String path, int fileSize, int bufferSize, int random)
         raf.close();
       }
     }

Review comment:
       We may use ThreadLocalRandom.current().nextBytes(buffer) to fill the buffer.
   ```
       final byte[] buffer = new byte[Math.toIntExact(bufferSize)];
       try(RandomAccessFile raf = new RandomAccessFile(path, "rw")) {
         while (offset < fileSize) {
           final long remaining = fileSize - offset;
           final long chunkSize = Math.min(remaining, bufferSize);
           ThreadLocalRandom.current().nextBytes(buffer);
           raf.write(buffer, 0, Math.toIntExact(chunkSize));
           offset += chunkSize;
         }
       }
   ```

##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Client.java
##########
@@ -121,27 +133,61 @@ protected void stop(RaftClient client) throws IOException {
     System.exit(0);
   }
 
-  protected List<String> generateFiles() throws IOException {
+  public String getPath(String fileName) {
+    int hash = fileName.hashCode() % storageDir.size();
+    return new File(storageDir.get(Math.abs(hash)), fileName).getAbsolutePath();
+  }
+
+  protected void dropCache() throws InterruptedException, IOException {
+    String[] cmds = {"/bin/sh","-c","echo 3 > /proc/sys/vm/drop_caches"};
+    Process pro = Runtime.getRuntime().exec(cmds);
+    pro.waitFor();

Review comment:
       Let's try-catch it since the command is platform dependent.
   ```
       try {
         Process pro = Runtime.getRuntime().exec(cmds);
         pro.waitFor();
       } catch (Throwable t) {
         LOG.warn("Failed to run command " + Arrays.toString(cmds), t);
       }
   ```

##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Server.java
##########
@@ -62,6 +59,18 @@
       required = true)
   private List<File> storageDir = new ArrayList<>();
 
+  @Parameter(names = {"--writeThreadNum"}, description = "Number of write thread")
+  private int writeThreadNum = 10;
+
+  @Parameter(names = {"--readThreadNum"}, description = "Number of read thread")
+  private int readThreadNum = 10;

Review comment:
       Let's set the default values of writeThreadNum and readThreadNum to 20.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org