簡體   English   中英

Apache Camel SQL批量插入需要很長時間

[英]Apache Camel SQL Batch insertion taking long time

我正在使用Apache Camel SQL批量插入過程。

  1. 我的應用程序是從Active MQ讀取票據,其中包含大約2000張票據。

  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. 下面是我的java代碼:

     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中有大約120個票證時,SQL批處理應該已經開始將值插入到數據庫中。 但它需要花費更多的時間。 當ActiveMQ中有大約500張票時,它開始插入過程。 anyboody可以幫助優化插入過程嗎? 還是其他方法?

問題在於ActiceMQ的消費者數量。

當我將消費者數量更改回1時,批次會按時更新。

實際上,當消費者數量為10時,門票被並行消耗。 這意味着,對於有10個消費者的activemq消費的100張票,每個消費者大約有10張票,因此增加了更多的時間。 當任何一個消費者獲得100張票時,該批次就會得到更新。

因此,將使用者計數更改為1會使所有票證由單個使用者處理,從而執行批量更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM