在有限的时间内针对多个查询的最佳解决方案 [英] Best solution for multiple queries in a limited time

查看:113
本文介绍了在有限的时间内针对多个查询的最佳解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于MORPG Hack'n'Slash游戏,我目前正在使用Neo4j,其模式如下:

For a MORPG Hack'n'Slash game i am currently using Neo4j with a pattern like this :

我有一个Neo4J连接器类,用于创建我的连接并实现Singleton,每个xxxMapper类都使用此实例,并调用Neo4jConnetor.getInstance().query(String query)来返回查询结果的迭代器.

I have a Neo4J connector class, creating my connection and implementing Singleton and this instance is used by every xxxMapper classes, calling Neo4jConnetor.getInstance().query(String query) which returns the iterator of the queryresult.

Atm我在问自己一个问题,游戏每秒将有大量查询(例如每位玩家每秒5个查询).因此,就性能而言,我不知道该使用哪种模式,是否应该继续使用我的Singleton系统或使用Neo4jConnector池或其他我不知道的其他系统.

Atm I'm asking myself a question, the game will have a ton of queries per second (like 5 per player per second). So I don't know, in terms of perfs, which pattern to use, if I should keep using my Singleton system or using another one like a pool of Neo4jConnector or anything else i don't know yet.

这是连接器类:

public class Neo4jConnector{

    private String urlRest;
    private String url = "http://localhost:7474";
    protected QueryEngine<?> engine;
    protected static Neo4jConnector INSTANCE = new Neo4jConnector();

    private Neo4jConnector(){
        urlRest = url+"/db/data";
        final RestAPI graphDb = new RestAPIFacade(urlRest);
        engine = new RestCypherQueryEngine(graphDb);
    }

    public static Neo4jConnector getInstance(){
        if (INSTANCE == null)
        { 
            INSTANCE = new Neo4jConnector();
        }
        return INSTANCE;
    }

    @SuppressWarnings("unchecked")
    public Iterator<Map<String, Object>> query(String query){
        QueryResult<Map<String, Object>> row = (QueryResult<Map<String, Object>>) engine.query(query, Collections.EMPTY_MAP);
        return row.iterator();
    }
}

以及此类的示例调用:

Iterator<Map<String, Object>> iterator = Neo4jConnector.getInstance().query("optional Match(u:User{username:'"+username+"'}) return u.password as password, u.id as id");

推荐答案

Neo4j的嵌入式GraphDatabaseService并非池化且线程安全的.

Neo4j's embedded GraphDatabaseService is not pooled and threadsafe.

我不推荐RestGraphDatabase和朋友,因为它运行缓慢且过时.

I would not recommend RestGraphDatabase and friends, because it is slow and outdated.

只需使用参数而不是文字字符串,并且不要使用可选的匹配即可开始查询.

Just use parameters instead of literal strings and don't use optional match to start a query.

如果您希望获得更快的访问权限,请查看JDBC驱动程序(该驱动程序将很快更新).

If you look for faster access look into the JDBC driver (which will be updated soonish).

这篇关于在有限的时间内针对多个查询的最佳解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆