骡子批处理工作耗时太长,无法丰富数据

时间:2017-07-19 15:45:08

标签: mule batch-processing

我正在尝试丰富数据以创建XML文件。

第一个查询执行Group By以获取事务标头。

第二个查询获取与同一文件中的标头匹配的所有记录(详细信息),以丰富消息。

问题是运行丰富数据的查询需要大约一秒钟。我需要为184,764个头文件运行此过程。每个标题一秒钟,这项工作将花费太长时间。有没有办法完成同样的事情,而无需查询数据库的详细信息?是否可以先加载所有记录并从内存中获取详细信息?这是代码:

    <db:generic-config name="Generic_Database_Configuration" url="${db.url}" 
driverClassName="${driver.class.name}" doc:name="Generic Database 
Configuration"/>
<data-mapper:config name="List_Map__To_List_Map_" 
transformationGraphPath="list_map__to_list_map_.grf" 
doc:name="List_Map__To_List_Map_"/>
<data-mapper:config name="List_Map__To_XML_1" 
transformationGraphPath="list_map__to_xml_1.grf" 
doc:name="List_Map__To_XML_1"/>
<batch:job name="OrceTransactionImportBatch">
    <batch:input>
        <db:select config-ref="Generic_Database_Configuration" 
doc:name="Database">
            <db:parameterized-query><![CDATA[SELECT TRANDATED, STORED, REG#D 
AS REG_D, TRAN#D AS TRAN_D, VIP#D AS VIP_D, VIP#D AS VIPNO, SUM(RETAIL*QTY) 
AS TOTAL,
CONCAT(SUBSTRING(TRANDATED,1,4),                    
CONCAT('-',CONCAT(SUBSTRING(TRANDATED,5,2),                
CONCAT('-',CONCAT(SUBSTRING(TRANDATED,7,2),'T00:00:00'))))) AS 
BusinessDayDate
FROM ORCTEXDTLP
WHERE DGROUPID IN (SELECT HGROUPID FROM ORCTEXHDRP WHERE HPRCFLAG = 'P')
GROUP BY STORED, TRANDATED, REG#D, TRAN#D, VIP#D
FETCH FIRST 60 ROWS ONLY]]></db:parameterized-query>
        </db:select>
        <logger message="before mapper..." level="INFO" doc:name="before 
mapper..."/>
    </batch:input>
    <batch:process-records>
        <batch:step name="Batch_Step">
            <data-mapper:transform config-ref="List_Map__To_List_Map_" 
doc:name="List&lt;Map&gt; To List&lt;Map&gt;"/>
            <logger message="before enricher..." level="INFO" 
doc:name="before enricher..."/>
        </batch:step>
        <batch:step name="Batch_Step1">
            <logger message="BEFORE FOR EACH..." level="INFO" 
doc:name="Logger"/>
            <enricher target="#[variable:LineItem]" doc:name="Message 
Enricher">
                <db:select config-ref="Generic_Database_Configuration" 
doc:name="Database">
                    <db:parameterized-query><![CDATA[SELECT TRANCODED, 
CONCAT(SUBSTRING(TRANDATED,1,4),                    
CONCAT('-',CONCAT(SUBSTRING(TRANDATED,5,2),                
CONCAT('-',CONCAT(SUBSTRING(TRANDATED,7,2),'T00:00:00'))))) AS 
BusinessDayDate, STORED AS RetailStoreID, TRAN#D AS TransactionNumber, REG#D 
AS WorkstationID, RETAIL AS TransactionGrandAmount, VIP#D AS AlternateID, 
DISCOUNT, VOUCHER#D AS VOUCHER_D, TRIM(SKU#) AS ItemID, A03K2 AS 
UnitCostPrice, RETAIL AS RegularSalesUnitPrice, (RETAIL*QTY) AS 
ExtendedAmount, QTY AS Quantity, ROW_NUMBER() OVER () rownumber, 
(RETAIL*QTY) AS ActualRetail, 
VOUCHERCD AS VoucherCode, VOUCHER#D AS VoucherNumber
FROM FBF02P 
LEFT OUTER JOIN KSK2P ON SKUK2 = SKU#
WHERE TRANDATED = #[payload[0]['TRANDATED']] AND STORED = #[payload[0]                
['STORED']] AND REG#D = #[payload[0]['REG_D']] AND TRAN#D = #[payload[0]        
['TRAN_D']]]]></db:parameterized-query>
                </db:select>
            </enricher>
            <expression-component doc:name="Expression"><![CDATA[#
[payload[0].LineItem=flowVars.LineItem]]]></expression-component>
            <logger message="#[payload[0]['TRAN_D']]" level="INFO" 
doc:name="Logger"/>
        </batch:step>
        <batch:step name="Batch_Step2">
            <batch:commit streaming="true" doc:name="Batch Commit">
                <data-mapper:transform config-ref="List_Map__To_XML_1" 
doc:name="List&lt;Map&gt; To XML"/>
                <file:outbound-endpoint path="${output.path}" 
outputPattern="TranImport#[server.dateTime.format('yyyyMMdd_HHmmss')].xml" 
responseTimeout="10000" doc:name="File"/>
            </batch:commit>
        </batch:step>
    </batch:process-records>
    <batch:on-complete>
        <logger message="DONE..." level="INFO" doc:name="Logger"/>
    </batch:on-complete>
</batch:job>
<flow name="OrceTransactionImportFlow">
        <poll doc:name="Poll">
            <fixed-frequency-scheduler frequency="1" timeUnit="DAYS"/>
            <db:update config-ref="Generic_Database_Configuration" 
doc:name="Database">
            <db:parameterized-query><![CDATA[UPDATE ORCTEXHDRP
SET HPRCFLAG = 'P'
WHERE HPRCFLAG = '' OR HPRCFLAG = 'P']]></db:parameterized-query>
            </db:update>
        </poll>
    <choice doc:name="Choice">
        <when expression="#[payload == 0]">
            <logger message="Zero payload..." level="INFO" 
doc:name="Logger"/>
        </when>
        <otherwise>
            <batch:execute name="OrceTransactionImportBatch" 
doc:name="OrceTransactionImportBatch"/>
        </otherwise>
    </choice>
</flow>

1 个答案:

答案 0 :(得分:0)

在数据库连接器配置中,您应该设置连接池配置文件。