请考虑以下代码:
我正在发送一个SOAP请求,传递一个数字,并得到7-8个字段的信息。我在soap信封中传递的号码是从一个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中的17万条记录中,由于请求超时,在Server 2008中插入19000条记录之后,它就停止了。
有什么方法可以使我的代码高效吗?阅读某处的人建议使用<cfthread>?
发布于 2014-09-05 06:41:24
增加http超时+页面超时。如果您正在处理如此大的记录,请始终尝试将记录划分为小块。
在循环中插入17k记录并调用insert查询是不可行的。
您可以通过除法(例如: 17000/2000 =9个文本/ SQL文件)和使用SQL从SQL或文本文件将数据导入DB来提高性能。
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”中添加新行,字段中删除“:,:”
https://stackoverflow.com/questions/25671329
复制相似问题