0

これは私を夢中にさせています。CF memcached ラッパーの構築を試みました。次のような memcached.cfc コンポーネントがあります。

<cfset this.m = arraynew(1)>

<cffunction name="init" access="public" output="false">
    <cfif not isdefined("application.memcached")
    ....
            <cfscript>
            setup();
                </cfscript>
         ...
            <cfset application.memcached = this>
          </cfif>
   <cfreturn application.memcached>
</cffunction>


<cffunction name="setup" access="private" output="false">
    <cftry>
        <cfset this.m = arraynew(1)>
        <cfloop from="1" to="#this.poolSize#" index="i">
            <cfset this.m[i] = createClient()>
        </cfloop>
        <cflog application="no" file="memcached" text="Successfully set up #this.poolSize# new memcache clients">
        <cfcatch>
            <cflog application="no" file="memcached" text="Exception in setup() while setting up the pool: type: #cfcatch.type#, message: #cfcatch.message#, detail: #cfcatch.detail#">
        </cfcatch>
    </cftry>
</cffunction>


<cffunction name="createClient" access="private" output="false">
    <cfset var AU = createObject("java", "net.spy.memcached.AddrUtil").init()>
    <cfset var c = createObject("java", "net.spy.memcached.MemcachedClient").init(AU.getAddresses("127.0.0.1:11211"))>
    <cfreturn c>
</cffunction>

<cffunction name="getCache" access="public" returntype="any" output="false">
    <cfset idx = ceiling(rand() * 20)>
    <cfreturn application.memcached.m[idx]>
</cffunction>

奇妙なことは、30 分ほど実行した後、getCache が失敗し始め、idx の位置にある application.memcached.m 配列に項目がないということです。

これはどのように起こっているのでしょうか?CF配列は弱参照か何かを使用していますか? アレイに 20 個のクライアントが配置されると、アレイは常に満杯のままになるはずですか?

新しいクライアントごとに新しいスレッドが生成されるため、クライアントへの参照が失われると、クライアントをシャットダウンする方法があり、そのスレッドはそこに永久に残り、メモリを消費します。何が足りないのですか?

4

3 に答える 3

1

アプリケーション スコープが削除される可能性があります。そのための適切なタイムアウトを指定する必要があります。また、デバッグ目的で OnApplication が呼び出されるかどうかにかかわらず、これをログに記録する必要があります。

于 2011-06-29T07:14:10.397 に答える
1

この memcached CFC はいつ使用されますか? リクエストごと?'i' および 'idx' 変数の var スコープの欠如は、それと関係がある可能性があります。これがなぜ不可欠なのかを簡単に説明する、私が書いたいくつかの記事を次に示します。

http://duncan99.wordpress.com/2009/03/12/the-importance-of-var-scoping/

http://duncan99.wordpress.com/2009/03/16/the-importance-of-var-scoping-part-2/

于 2011-06-29T09:44:25.953 に答える