1

请考虑以下代码:

我正在发送一个 SOAP 请求,传递一个数字并返回 7-8 个信息字段。我在我的肥皂信封中传递的数字是从 170,000 条记录的 CSV 文件中提取的。这是我正在做的代码片段:

<cffile action="READ" file="http://filepath/Myfile.csv" variable="FileContent">
<cfset CSVArray = CSVtoArray(FileContent)>

<cfset CSVArrayLength = ArrayLen(CSVarray)>

Total Records:<cfdump var="#CSVArrayLength#" >

<cfloop index="LoopCount" from = "2" to = "#CSVArrayLength#">

<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:vtsInfoLookup" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:vtsInfoLookup">
    <SOAP-ENV:Header>
        <userName>xyz</userName>
        <password>JiunskeT1</password>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
           <infoLookup SOAP-ENV:EncodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >

                  <Number><cfoutput>#CSVArray[LoopCount][2]#</cfoutput></Number> 
               <userName>xyz</userName>
               <password>passwd</password> 
           </infoLookup>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

</cfsavecontent>

<cfhttp url ="https://myurl/abc.php?wsdl"  method = "post"  result =   "httpResponse" throwonerror=   "Yes">
    <cfhttpparam type="header" name="accept-encoding" value="no-compression" />
            <cfhttpparam type="header" name="content-type" value="application/soap+xml">

            <cfhttpparam type="header" name="content-length" value="#len(soap)#">
            <cfhttpparam type="xml" value="#trim(soap)#">

</cfhttp>

<cfset XMLResponse = XmlParse(httpResponse.fileContent.Trim()) />
    <cfset arrNumber = XmlSearch(XMLResponse,"//*[name()='Number']") />
    <cfset Number = trim(arrNumber[1].xmlText)>


    // Similarly parsing for other 7-8 fields


     <cfquery name="vQuery" datasource="XX.XX.X.XXX">

    INSERT INTO 



          VALUES (<cfqueryparam cfsqltype = "cf_sql_varchar" value = "#trim(Number)#" null = "#NOT len(trim(Number))#"/>,

                     // 7 - 8 fields more here
                   )



    </cfquery>   


</cfloop>

我从 2 开始的原因是我的 CSV 文件在第一行有列名。数字从 CSV 中的第二行开始。这就是我#CSVArray[LoopCount][2]#上面提到的原因

我已经使用了这里提到的 CSVToarray 函数

因为,在我的服务器-->设置中,超时请求(秒)的值设置为 7200 秒,所以我的请求在 2 小时后超时并显示错误消息:

请求已超过允许的时间限制 标签:cfhttp

因此,在 CSV 中的 170,000 条记录中,由于请求超时,它在 SQL Server 2008 中插入 19000 条记录后停止。

有没有办法让我的代码高效?在某个地方读到有人建议使用<cfthread>?

4

1 回答 1

2

增加http超时+页面超时。如果您正在处理如此大量的记录,请始终尝试将记录分成小块。

在循环中插入 17k 条记录并调用插入查询是不可行的。

您可以简单地通过划分来提高性能(例如:17000/2000 = 9 个文本/SQL 文件)并使用 SQL 功能将数据从 SQL 或文本文件导入数据库。

queryObj = new query();
queryObj.setDatasource(session.datasource);
result = queryObj.execute(sql="LOAD DATA INFILE '#VARIABLES.textPath#' INTO TABLE tblEmployee FIELDS TERMINATED BY ':,:' LINES TERMINATED BY '\r\n'  (emp_Name,emp_City)");

在文本文件中:新行添加到新行 '\r\n' 中,字段用 ':,:' 分隔

于 2014-09-05T06:41:24.733 回答