0

I am developing in Google App Engine since one year ago and I am understanding how important is the warmup time for instances. So I ended up with an idea: is it possible to cache singleton in memcache? For example I am using the singleton pattern for JDO PersistenceManagerFactory.

Here is my actual code (as described in documentation):

    private static PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory(<my-name>);

Does it have any sense something like extend the JDOHelper and write a function like this one:

public static PersistenceManagerFactory getPersistenceManagerFactoryCached(String name) {
    MemcacheService cache = MemcacheServiceFactory.getMemcacheService();;
    PersistenceManagerFactory staticPMF= null;
    if (cache.contains("JDO_PMF")) {
        staticPMF = (PersistenceManagerFactory) cache.get("JDO_PMF");
    } else {
        staticPMF = JDOHelper.getPersistenceManagerFactory(name);
        cache.put("JDO_PMF", staticPMF);
    }
    return staticPMF;
}

My idea should be to cache the PersistenceManagerFactory to speed-up the first instance and then use this one as the singleton:

private static PersistenceManagerFactory pmfInstance = JDOHelperCached.getPersistenceManagerFactory(<my-name>);
4

1 に答える 1

1

編集: このリンクを見つけたところ、 https: //groups.google.com/group/google-appengine-java/browse_thread/thread/1b90fae408b52d49 の Ikai Lan によると、異なるインスタンスは PersistenceManagerFactory インスタンスを共有できないようです

================================================== ========================

私はこのアイデアが好きで、すぐに自分のコードを試してみましたが、残念ながら次のようなエラーが発生しました:

javax.jdo.JDOFatalUserException: No available StoreManager found for the datastore URL key "". Please make sure you have all relevant plugins in the CLASSPATH (e.g datanucleus-rdbms?, datanucleus-db4o?), and consider setting the persistence property "datanucleus.storeManagerType" to the type of store you are using e.g rdbms, db4o

私だけの問題かもしれませんが、現段階では判断できません。

私はこれについてもっと考えました:

したがって、あなたが提案した方法が機能しており、必要な適切なファクトリを取得できると仮定しましょう。実際のパフォーマンスは、memcache の使用方法によって異なります。

1) memcache に大量の書き込みがある場合、PersistenceManagerFactory がキャッシュから頻繁に追い出される可能性があることを意味します。つまり、再度作成する必要があります。

2) 新しい PersistenceManagerFactory を作成するたびに、キャッシュに入れることになりますが、私の経験によると、GAE を扱うのは非常に不安定であり、部分的に入れるのに予想よりもはるかに長い時間がかかることがあります。

于 2012-06-05T23:53:00.057 に答える