2016-10-26 6 views
9

Apache Camel SQL 배치 삽입 프로세스를 사용하고 있습니다.Apache Camel SQL 일괄 삽입 시간이 오래 걸림

  1. 내 응용 프로그램은 약 2000 개의 티켓이 포함 된 활성 MQ에서 티켓을 읽습니다.

  2. 나는 100

  3. 로 배치를 업데이트 한 다음 내가 발사하고 쿼리는 다음과 같이

    sql.subs.insertCdr= insert into subscription_logs(master_id,request_type,req_desc,msisdn,amount,status,resp_code,resp_desc,channel,transaction_id,se_mode,be_mode,sub_type,sub_timeleft,srv_name,srv_id,start_date,end_date,operator,circle,country,time_offset,retry_count,user_status,previous_state,se_reqrecvtime,se_respsenttime,be_reqsenttime,be_resprecvtime,cp_id,cp_name,sub_srvname,sub_srvid,msg_senderid,msg_text,call_back_url,call_back_resp,client_ip,se_sysIp,language,cp_callbackurlhittime,action,alert,notification_url,notification_resp) values(:#masterId, :#requestType,:#reqDesc,:#msisdnCdr,:#price,:#status,:#responseCode,:#reason,:#channel,:#transactionId,:#seMode,:#beMode,:#subType,:#subTimeLeft,:#serviceName,:#serviceId,:#subStartDate,:#cdrEndDate,:#operator,:#circle,:#country,:#timeOffset,:#retryCount,:#userStatus,:#previousState,:#seReqRecvTime,:#seRespSentTime,:#beReqSentTime,:#beRespRecvTime,:#cpId,:#cpName,:#subServiceName,:#subServiceId,:#shortCode,:#message,:#callBackUrl,:#callBackResp,:#clientIp,:#seSysIp,:#language,:#cpCallbackUrlHitTime,:#action,:#alert,:#notificationUrl,:#notificationResponse)

  4. 는 SQL 배치 경로가 정의됩니다

    <pipeline> 
        <log message="Going to insert in database"></log> 
        <transform> 
         <method ref="insertionBean" method="subsBatchInsertion"></method> 
        </transform> 
        <choice> 
         <when> 
          <simple>${in.header.subsCount} == ${properties:batch.size}</simple> 
          <to uri="sql:{{sql.subs.insertCdr}}?batch=true"></to> 
          <log message="Inserted rows ${body}"></log> 
         </when> 
        </choice> 
    </pipeline> 
    
  5. 아래 자바 코드 :

    약 120 권의 ActiveMQ에서, SQL 일괄 처리가 데이터베이스에서 값을 삽입하기 시작해야있을 때
    public List<Map<String, Object>> subsBatchInsertion(Exchange exchange) { 
    if (subsBatchCounter > batchSize) { 
        subsPayLoad.clear(); 
        subsBatchCounter = 1; 
    } 
    subsPayLoad.add(generateInsert(exchange.getIn().getBody(SubscriptionCdr.class))); 
    exchange.getIn().setHeader("subsCount", subsBatchCounter); 
    subsBatchCounter++; 
    return subsPayLoad; 
    } 
    
    public Map<String, Object> generateInsert(Cdr cdr) { 
    Map<String, Object> insert = new HashMap<String, Object>(); 
    try { 
        insert = BeanUtils.describe(cdr); 
    } catch (Exception e) { 
        Logger.sysLog(LogValues.error, this.getClass().getName()+" | "+Thread.currentThread().getStackTrace()[1].getMethodName(), coreException.GetStack(e)); 
    } 
    for (String name : insert.keySet()) { 
        Logger.sysLog(LogValues.APP_DEBUG, this.getClass().getName(), name + ":"+ insert.get(name) + "\t"); 
    } 
    return insert; 
    } 
    

이제 문제입니다. 그러나 그것은 더 많은 시간을 필요로합니다. ActiveMQ에서 약 500 티켓이있을 때 삽입 프로세스를 시작합니다. 삽입 프로세스를 최적화하는 데 아무 도움이 될 수 있습니까? 또는 다른 방법이 있습니까?

답변

6

문제는 ActiceMQ 소비자 번호에서 발생했습니다.

소비자 수를 다시 1로 변경하면 일괄 적으로 번 업데이트됩니다.

실제로 소비자 수가 10 명일 때 티켓은 병렬로 소비되었습니다. 즉, 10 명의 고객이 activemq에서 소비 한 100 개의 티켓에는 각 소비자마다 약 10 개의 티켓이 있으므로 더 많은 시간이 추가됩니다. 소비자 중 한 명이 100 장의 티켓을 받으면 배치가 업데이트되고있었습니다.

그래서 모든 티켓 단일 소비자가 처리하게 1 소비자 수를 변경함으로써 일괄 업데이트를 잘 수행.