You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/01/23 07:34:49 UTC

[GitHub] wu-sheng commented on issue #2195: Register lock refactor

wu-sheng commented on issue #2195: Register lock refactor
URL: https://github.com/apache/incubator-skywalking/pull/2195#issuecomment-456699686
 
 
   I have run the following test codes to verify the new mechanism.
   
   ```java
       public static void main(String[] args) {
           TestThread[] threads = new TestThread[10];
           for (int i = 0; i < 10; i++) {
               threads[i] = new TestThread();
           }
   
           long time1 = System.currentTimeMillis();
           for (Thread thread : threads) {
               thread.start();
           }
   
           for (Thread thread : threads) {
               try {
                   thread.join();
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
   
           long time2 = System.currentTimeMillis();
           System.out.println("execute time:" + (time2 - time1) + "ms");
           int error = 0;
           int success = 0;
           int conflict = 0;
   
           HashMap<Integer, Object> checkset = new HashMap<>();
           for (TestThread thread : threads) {
               error += thread.error;
               success += thread.ids.size();
               for (Object id : thread.ids) {
                   Integer idi = (Integer)id;
                   if (checkset.containsKey(idi)) {
                       conflict++;
                   } else {
                       checkset.put(idi, new Object());
                   }
               }
           }
           System.out.println("getId failure:" + error);
           System.out.println("getId success:" + success);
           System.out.println("getId conflict:" + conflict);
       }
   
       private static class TestThread extends Thread {
           private volatile int i = 100;
           private ArrayList ids = new ArrayList(i);
           private volatile int error = 0;
   
           @Override public void run() {
               try {
                   Thread.sleep(50L);
               } catch (InterruptedException e) {
               }
               RegisterSource source = new RegisterSource() {
                   @Override public int remoteHashCode() {
                       return 0;
                   }
   
                   @Override public void deserialize(RemoteData remoteData) {
   
                   }
   
                   @Override public RemoteData.Builder serialize() {
                       return null;
                   }
   
                   @Override public String id() {
                       return null;
                   }
               };
   
               ElasticSearchClient client = new ElasticSearchClient("localhost:9200", null);
               client.connect();
   
               RegisterLockDAOImpl dao = new RegisterLockDAOImpl(client);
               while (i-- > 0) {
                   try {
                       int id = dao.getId(Scope.ServiceInventory, source);
                       if (id == 0) {
                           error++;
                       } else {
                           ids.add(id);
                       }
                   } catch (Exception e) {
                       error++;
                   }
               }
           }
       }
   ```
   
   The output is 
   ```
   execute time:2894ms
   getId failure:829
   getId success:171
   getId conflict:0
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services