Last active
July 13, 2021 15:55
-
-
Save jbarotin/9a99b185b2ded34f08cabe3bfb614e19 to your computer and use it in GitHub Desktop.
This objet help to highlight a "memory leak" of the seaweedfs java client (launch with args "100 50" for example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package seaweed.test; | |
import seaweedfs.client.FilerClient; | |
import seaweedfs.client.SeaweedOutputStream; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class Perf { | |
public static String getRandom(int size) { | |
Random r = new Random(); | |
String alphabet = "123456789acbdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ;,/:!"; | |
StringBuilder randomString = new StringBuilder(); | |
for (int i = 0; i < size; i++) { | |
randomString.append(alphabet.charAt(r.nextInt(alphabet.length()))); | |
} | |
return randomString.toString(); | |
} | |
public static void main(String[] args) { | |
FilerClient filerClient = new FilerClient("localhost", 18888); | |
Random random = new Random(); | |
List<Runnable> threads = new ArrayList<>(); | |
for (int i = 0; i < Integer.valueOf(args[0]); i++) { | |
Thread thread = new Thread() { | |
@Override | |
public void run() { | |
for(int j = 0; j < Integer.valueOf(args[1]); j++) { | |
SeaweedOutputStream seaweedOutputStream = new SeaweedOutputStream(filerClient, "/subdir" + random.nextInt(), ""); | |
try { | |
seaweedOutputStream.write(getRandom(10 * 1024).getBytes()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
seaweedOutputStream.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
}; | |
thread.start(); | |
threads.add(thread); | |
} | |
try { | |
Thread.sleep(100000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment