Why is the getInstance method of tikv-java-client session prohibited from use?

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tikv-java-client session 的getInstance方法禁止使用是出于什么考虑

| username: llllllll

May I ask why the getInstance method was disabled in this commit do not use TiSession.getInstance by marsishandsome · Pull Request #117 · tikv/client-java · GitHub? Currently, I am noticing some performance issues.

| username: Billmay表妹 | Original post link

If I’m not mistaken, it was probably disabled due to some irreparable bugs.

| username: ljluestc | Original post link

The reason for prohibiting the getInstance method in the code you shared is not explicitly mentioned in the code itself. However, I can provide some insights based on the changes made in the code.

In the original code, the Snapshot class had two constructors, one accepting TiConfiguration and the other accepting TiSession. Both constructors used the getInstance method of TiSession to initialize the session field:

this.session = TiSession.getInstance(conf);

In the updated code, the getInstance method is marked as deprecated and is no longer used. Instead, the session field is directly assigned using the provided TiSession object:

this.session = session;

The reason for deprecating and prohibiting the getInstance method might be to prevent the creation of new instances of TiSession using a static method and to promote the use of dependency injection or other methods of managing TiSession instances.

Regarding the performance issues you mentioned, please note that the changes in the code you provided are not directly related to performance optimization. The performance issues you are experiencing might be caused by other factors in your codebase or environment. It is necessary to analyze and describe your specific use case to determine the root cause of the performance issues.

I recommend using performance profiling tools and performance monitoring to analyze performance bottlenecks, such as database queries, network communication, or resource utilization. You might also consider reviewing TiDB and TiKV configuration settings to ensure they are properly optimized for your workload. Upgrading to a newer version of TiDB that includes performance improvements might also be beneficial.