我有一个交易虚拟物品的应用程序,并且有一个单独的页面可以获取我的所有帐户,每个帐户创建一个首先记录帐户的线程,然后在会话处于活动状态时搜索和购买项目。我应该指出这是我第一次使用cfthread。
我遇到了问题。每30分钟(如果不是更少)我的ColdFusion服务器停止运行,我必须重新启动服务。重新启动服务后,我会检查日志,并且有错误表示“GC Overhead Limit Exceeded”。
我在网上看了很多,但cfthread对我来说是新的,JVM也是如此,它的运作方式也是如此。我正在运行CF10企业版并加载了服务器监视器,当然我可以看到JVM内存使用量的增长和增长直到达到限制(刚才我把它设置为2gb,就像我设置得更高一样记忆似乎更快填满了)。即使我在监视器中选择“运行GC”选项,它也不会大大减少内存使用量,如果有的话。
这可能与我的代码有关吗?目前我创建的线程不到50个但是当我向应用程序添加更多帐户时,需要的线程就越多。
以下是页面中的代码......
<script>
/* RELOAD PAGE EVERY 65 MINUTES */
setTimeout(function(){
window.location.reload(1);
}, 3900000);
</script>
<!--- GET ACTIVE ACCOUNTS --->
<cfquery name="getLogins" datasource="myDB">
SELECT * FROM Logins WHERE active = 1
</cfquery>
<!--- LOOP THROUGH ACCOUNT --->
<cfloop query="getLogins">
<!--- HAVE A SLEEP SO IP DOESN'T GET FLAGGED FOR SENDING TOO MANY REQUESTS AT ONCE --->
<cfset Sleep(30000) />
<!--- CREATE THREAD FOR ACCOUNT --->
<cfthread
name="#getLogins.accountName#"
action="run"
accountName="#Trim(getLogins.accountName)#"
email="#Trim(getLogins.email)#"
password="#Trim(getLogins.password)#"
resourceId="#Trim(getLogins.resourceID)#">
<!--- DEFAULT SESSION VARIABLES --->
<cfset SESSION["#attributes.accountName#LoggedIn"] = 0 />
<cfset SESSION["#attributes.accountName#LoginAttempts"] = 0 />
<!--- WHILE ACCOUNT NOT LOGGED IN AND LESS THAN 8 LOGIN ATTEMPTS MADE --->
<cfscript>
while (SESSION['#attributes.accountName#LoggedIn'] EQ 0 AND SESSION['#attributes.accountName#LoginAttempts'] LT 8) {
// ATTEMPT LOGIN
THREAD.logInAccount = Application.cfcs.Login.logInAccount(attributes.email,attributes.password);
// IF LOGIN ATTEMPT UNSUCCESSFUL
if (THREAD.logInAccount EQ 0) {
// INCREASE ATTEMPT COUNT
SESSION['#attributes.accountName#LoginAttempts'] = SESSION['#attributes.accountName#LoginAttempts'] + 1;
}
// ELSE IF RETURNED VALUE IS 481 THEN ACCOUNT IS LOCKED
else if (THREAD.logInAccount EQ 481) {
// SET LOGIN ATTEMPT COUNT TO STOP LOOP
SESSION['#attributes.accountName#LoginAttempts'] = 8;
// UPDATE ACCOUNT TO MARK AS LOCKED
THREAD.updLogin = Application.cfcs.Login.updLogin(attributes.email);
}
}
</cfscript>
<!--- IF ACCOUNT LOGGED IN --->
<cfif SESSION['#attributes.accountName#LoggedIn'] EQ 1>
<!--- SET ID FOR SEARCHING --->
<cfset THREAD.definitionID = attributes.resourceID - 1610612736 />
<!--- WHILE ACCOUNT LOGGED IN --->
<cfloop condition="SESSION['#attributes.accountName#LoggedIn'] EQUALS 1">
<!--- GET LATEST LOWEST BUY NOW PRICE --->
<cfquery name="THREAD.getMinBIN" datasource="FUT" cachedWithin="#CreateTimeSpan(0,0,1,0)#">
SELECT TOP 1 * FROM v_FUT14BINPrices WHERE resourceID = #attributes.resourceId# ORDER BY lastUpdated DESC
</cfquery>
<!--- INCLUDE FILE THAT CALCULATES BUYING AND SELLING PRICES --->
<cfinclude template="sellingPrices.cfm" />
<!--- IF BIDDING PRICE HAS BEEN SET --->
<cfif StructKeyExists(THREAD,"biddingPrice")>
<!--- MAKE SEARCH REQUEST, TIMING THE REQUEST --->
<cfset THREAD.requestStart = GetTickCount() />
<cfset THREAD.search = Application.cfcs.Search.dosearchOld(attributes.resourceId,THREAD.biddingPrice,0) />
<cfset THREAD.requestDuration = GetTickCount() - THREAD.requestStart />
<!--- IF SEARCH CONTAINS FILE CONTENT --->
<cfif StructKeyExists(THREAD.search,"FileContent")>
<!--- DECLARE NUMBER OF RESULTS VARIABLE --->
<cfset THREAD.numResults = 0 />
<!--- IF JSON RETURNED --->
<cfif IsJSON(THREAD.search.FileContent)>
<!--- DESERIALIZE JSON --->
<cfset THREAD.searchResults = DeserializeJSON(THREAD.search.FileContent) />
<!--- IF PLAYER SEARCH RETURNS AUCTIONINFO STRUCT --->
<cfif StructKeyExists(THREAD.searchResults,"auctionInfo")>
<!--- SET NUMBER OF CARDS RETURNED FROM SEARCH --->
<cfset THREAD.numResults = ArrayLen(THREAD.searchResults.auctionInfo) />
<cfset THREAD.statusCode = "Successful" />
<cfif THREAD.numResults EQ 0>
<cfset THREAD.statusCode = "Successful - No Results" />
</cfif>
<!--- ELSE IF ERROR CODE RETURNED --->
<cfelseif StructKeyExists(THREAD.searchResults,"code")>
<cfset THREAD.statusCode = THREAD.searchResults.code />
<!--- IF CODE 401 THEN SESSION HAS EXPIRED --->
<cfif THREAD.statusCode EQ 401>
<!--- SET SESSION AS LOGGED OUT AND ATTEMPT SESSION REFRESH --->
<cfset SESSION['#attributes.accountName#LoggedIn'] = 0 />
<cfset THREAD.logInAccount = Application.cfcs.Login.logInAccount(attributes.email,attributes.password) />
</cfif>
<!--- ELSE SOMETHING ELSE HAS HAPPENED --->
<cfelse>
<cfset THREAD.statusCode = "Something Else - " & THREAD.searchResults.code />
</cfif>
<!--- IF RESULTS RETURNED --->
<cfif THREAD.numResults GT 0>
<!--- LOOP ROUND RESULTS AND CHECK IF MATCH BUYING CRITERIA --->
<cfloop index="i" from="1" to="#THREAD.numResults#">
<!--- ***SAFETY CHECK*** - ENSURE ID OF CURRENT CARD IS SAME AS ONE SEARCHING FOR --->
<cfif THREAD.searchResults.auctionInfo[i].itemData.resourceID EQ attributes.resourceId AND THREAD.getMinBIN.resourceID EQ attributes.resourceId>
<!--- ENSURE BIN PRICE SET AND IS LESS THAN SET BUYING PRICE --->
<cfif THREAD.searchResults.auctionInfo[i].buyNowPrice GT 0 AND THREAD.searchResults.auctionInfo[i].buyNowPrice LTE THREAD.biddingPrice>
<!--- SET AUCTION END TIME --->
<cfset THREAD.timeLeft = THREAD.searchResults.auctionInfo[i].expires />
<cfset THREAD.auctionEnds = DateAdd("s",THREAD.timeLeft,Now()) />
<!--- BUY CARD --->
<cfset THREAD.buyCard = Application.cfcs.Bid.doBIN(THREAD.searchResults.auctionInfo[i].tradeID,THREAD.searchResul ts.auctionInfo[i].buyNowPrice,THREAD.searchResults.auctionInfo[i].startingBid,THREAD.searc hResults.auctionInfo[i].itemData.ID,THREAD.searchResults.auctionInfo[i].itemData.resourceI D,THREAD.startPrice,THREAD.binPrice,THREAD.lowestBIN,THREAD.searchResults.auctionInfo[i].i temData.discardValue,THREAD.auctionEnds,THREAD.requestStart,THREAD.requestDuration) />
</cfif>
</cfif>
</cfloop>
</cfif>
<cfelse>
<cfset THREAD.statusCode = THREAD.search.FileContent />
</cfif>
<cfset THREAD.sleepDuration = 1000 - THREAD.requestDuration />
<cfif THREAD.sleepDuration GT 0><cfset Sleep(THREAD.sleepDuration) /></cfif>
</cfif>
<!--- INSERT SEARCH RECORD --->
<cfset THREAD.insSearchRecord = Application.cfcs.Search.insSearchRecord(THREAD.definitionID,THREAD.statusCode,THREAD.requ estDuration,THREAD.numResults,THREAD.biddingPrice) />
</cfif>
</cfloop>
</cfif>
</cfthread>
</cfloop>
我原本以为内存会保持大致相同的用法,因为每个循环执行相同的一组操作,所以一旦循环回到开始,那么我认为前一个循环将从内存中删除(释放空间)然后将执行相同的操作,因此相同的内存总量将被用尽,但似乎每个循环都被保存在内存中,这就是它正在增长的原因。
有人可以帮助我并就如何解决这个问题提供一些指导吗?如果您需要更多信息,请告诉我
提前致谢
答案 0 :(得分:0)
GC超额限制超出 - 几乎总是与您的JVM相关并且堆空间不足。几乎每个人都在评论中说的话。关于调试代码,我之前使用VisualVM查找应用程序服务器上的内存问题,这篇博文是描述如何设置和运行代码的最佳方式
http://boncode.blogspot.com.au/2010/04/cf-java-using-free-visualvm-tool-to.html