Comments (9)
Exception in thread "Thread-1" java.lang.NullPointerException
at com.vesoft.nebula.client.graph.GraphClientImpl.executeQuery(GraphClientImpl.java:134)
at com.coney.microservice.dashboard.NebulaTest$1.run(NebulaTest.java:43)
at java.lang.Thread.run(Thread.java:748)
from nebula-java.
From the code in client, I found that it should be connect, execute and close in same thread. If then, I need to create the client every time when access graph data. If connect and close frequently, will it affect the performance?
from nebula-java.
- What's the client version used in your test?
You just need to connect and close once for one socket, and switch space operator should be inner of sub-thread.
refer to issue #171
from nebula-java.
V1.1.0
from nebula-java.
I have put the switch space operation in sub-thread, but the result is same.
import cn.hutool.core.util.StrUtil;
import com.coney.microservice.dashboard.dto.DashboardDto;
import com.facebook.thrift.TException;
import com.google.common.collect.Lists;
import com.vesoft.nebula.client.graph.*;
import com.vesoft.nebula.data.Result;
import com.vesoft.nebula.graph.RowValue;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
@slf4j
public class NebulaTest {
public static void main(String[] args) throws InterruptedException {
GraphClientImpl graphClient = new GraphClientImpl("192.168.101.128", 3699);
graphClient.setUser("user");
graphClient.setPassword("password");
try {
graphClient.connect();
} catch (TException e) {
e.printStackTrace();
}
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
int code = graphClient.switchSpace("dashboard_graph");
System.out.println(code);
String query = "GO FROM uuid(\"{}\") OVER e_user_own_dashboard " +
"yield " +
"$$.tag_dashboard.id as ID, " +
"$$.tag_dashboard.name AS name, " +
"$$.tag_dashboard.description AS description, " +
"$$.tag_dashboard.status AS status, " +
"$$.tag_dashboard.content AS content";
ResultSet graphResult = graphClient.executeQuery(StrUtil.format(query, 1));
List<ResultSet.Result> rows = graphResult.getResults();
for (ResultSet.Result value : rows) {
log.info("ID: {}", value.getString("id"));
log.info("Name: {}", value.getString("name"));
}
} catch (ConnectionException e) {
e.printStackTrace();
} catch (NGQLException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
});
t.start();
t.join();
graphClient.close();
}
}
from nebula-java.
Exception in thread "Thread-1" java.lang.NullPointerException
at com.vesoft.nebula.client.graph.GraphClientImpl.execute(GraphClientImpl.java:107)
at com.vesoft.nebula.client.graph.GraphClientImpl.switchSpace(GraphClientImpl.java:88)
at com.coney.microservice.dashboard.NebulaTest$1.run(NebulaTest.java:32)
at java.lang.Thread.run(Thread.java:748)
from nebula-java.
As you said in #171
GraphClient graphClient = new GraphClientImpl(addresses);
graphClient.connect();
graphClient.executeQuery(gql);
new Thread(() -> {
graphClient.connect();
graphClient.executeQuery(gql);
}).start();
Tsocket will be opened twice, and they are in different thread.
For example:
My App is based on springboot, event request may be in different threads, so we call nebula api, like this.
graphClient.connect();
graphClient.executeQuery(gql);
graphClient.close();
that means we need to connect & close frequently, and socket will close frequently too, when there are a lot of requests.
I think it will cause performance issue, and socket will appear many TIME_WAIT which may occur connection issue in client side.
meanwhile, the v1.1.0 cannot support connection pool.
I don't know if anyone use it in springboot or othere micro service framework.
from nebula-java.
TCP 192.168.101.1:8960 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8961 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8962 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8963 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8964 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8965 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8966 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8967 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8968 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8969 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8970 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8971 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8972 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8973 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8974 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8975 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8976 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8977 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8978 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8979 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8980 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8981 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8982 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8983 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8984 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8985 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8986 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8987 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8988 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8989 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8990 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8991 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8992 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8993 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8994 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8995 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8996 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8997 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8998 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:8999 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:9000 192.168.101.128:3699 TIME_WAIT 0
TCP 192.168.101.1:9001 192.168.101.128:3699 TIME_WAIT 0
from nebula-java.
graphClient.close();
Your program throws NPE because the graphClient is closed in main thread, and NPE happens when sub-thread use graphClient to execute statements.
Sorry that Client 1.x does not support connection pool, if you want to support multi-thread query in SpringClould or SpringBoot, you can use pools to manage graphClient and graphClient's status to avoid graphClient being used by mutil-thread at the same time.
from nebula-java.
Related Issues (20)
- Support scala with zio HOT 4
- SessionPool在循环查询中阻塞 HOT 2
- Allow users to setHeader when using HTTP/2
- SessionPool 连接 3 节点集群时,一个节点宕机后,客户端无法连接,请问怎么设置集群可用度? HOT 3
- typo in examples? HOT 1
- The effective time of space is not friendly to testing HOT 2
- No worry
- Verify java client with custom header HOT 4
- the ordering of params was problematic, and it wasn't passing params correctly. HOT 2
- Does NebulaGraph support image storage? HOT 2
- [ent 3.6 zone]when upload to hdfs report error HOT 2
- 客户端连接集群问题 HOT 4
- When will storageclient provide the 'socketTimeout' parameter? HOT 1
- allow to config the charset for query statement
- support to config the version for graph client
- support to config the version for meta client
- support to auth for storage client
- nebula-java session会话 HOT 2
- Http2 example failed HOT 4
- support tls single authentication
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nebula-java.