Guest User

Untitled

a guest
Jul 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. package voldemort.performance;
  2.  
  3. import voldemort.client.ClientConfig;
  4. import voldemort.client.SocketStoreClientFactory;
  5. import voldemort.cluster.Cluster;
  6. import voldemort.store.StoreDefinition;
  7. import voldemort.store.metadata.MetadataStore;
  8. import voldemort.xml.ClusterMapper;
  9. import voldemort.xml.MappingException;
  10. import voldemort.xml.StoreDefinitionsMapper;
  11. import voldemort.client.protocol.RequestFormatType;
  12.  
  13. import java.io.StringReader;
  14. import java.util.List;
  15. import java.util.concurrent.ExecutorService;
  16. import java.util.concurrent.Executors;
  17. import java.util.concurrent.ThreadFactory;
  18.  
  19. public class MetadataStressTest {
  20.  
  21. public static void main(String[] args) throws Exception {
  22.  
  23. if(args.length < 3) {
  24. System.err.println("java voldemort.performance.MetadataStressTest url iterations selectors threads");
  25. System.exit(-1);
  26. }
  27.  
  28. String url = args[0];
  29. final int count = Integer.parseInt(args[1]);
  30. int numSelectors = Integer.parseInt(args[2]);
  31. int numThreads = Integer.parseInt(args[3]);
  32. ExecutorService executor = Executors.newFixedThreadPool(numThreads,
  33. new ThreadFactory() {
  34.  
  35. public Thread newThread(Runnable r) {
  36. Thread thread = new Thread(r);
  37. thread.setName("stress-test");
  38. return thread;
  39. }
  40. });
  41. try {
  42. final SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url)
  43. .setMaxThreads(numThreads)
  44. .setSelectors(numSelectors));
  45. for(int i = 0; i < numThreads; i++) {
  46. executor.submit(new Runnable() {
  47.  
  48. public void run() {
  49. for(int j = 0; j < count; j++) {
  50. try {
  51. String clusterXml = factory.bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
  52. Cluster cluster = new ClusterMapper().readCluster(new StringReader(clusterXml));
  53. String storesXml = factory.bootstrapMetadataWithRetries(MetadataStore.STORES_KEY);
  54. List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new StringReader(storesXml));
  55. System.out.println("ok " + j);
  56. } catch(MappingException me) {
  57. me.printStackTrace();
  58. System.exit(-1);
  59. } catch(Exception e) {
  60. // Don't fail on non XML exceptions, just continue on
  61. e.printStackTrace();
  62. }
  63. }
  64. }
  65. });
  66. }
  67.  
  68. } finally {
  69. executor.shutdown();
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment