You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "makssent (via GitHub)" <gi...@apache.org> on 2025/12/29 08:37:42 UTC
[I] Question about thread parallelization [shardingsphere]
makssent opened a new issue, #37569:
URL: https://github.com/apache/shardingsphere/issues/37569
## Question
Hi everyone, I’d like to clarify one nuance. As I understand it, scaling across nodes works as follows: we start with a single node that, условно, performs inserts using 6 threads. Then I scale the system to 2 nodes via ShardingSphere, and I effectively end up with two single nodes.
The question is: how will the threads behave in this case? Will the Proxy distribute these 6 threads across the nodes (roughly 3 per node), or will each node effectively handle 6 threads?
In the case where threads are “split,” it’s not entirely clear to me where a performance gain close to ×2 would come from. If the threads are divided, the load on each node becomes lower — that part is clear — but inserts are still executed with a total of 6 threads. In that case, it’s not completely clear what the point of having ×2 system capacity is if the total number of threads remains the same.
Also, in sysbench tests that I’ve seen, the configuration on each node specified `HikariPool.minimumPoolSize = 200` and `HikariPool.maximumPoolSize = 200`, after which sysbench was run with `--threads=200`. Am I correct in understanding that in this scenario, and with this configuration, each node effectively receives 200 threads?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3697970661
Thanks for the detailed info; sharing how we look at this:
- Threads: Proxy doesn’t create or split client threads. If sysbench runs 200 threads, both single and sharded setups see 200.
- Frontend vs backend connections: Client→Proxy are frontend; backend pools are per data source. With two shards and maxPoolSize=200, Proxy can open up to 200 per shard (~400 total), but actual usage follows routing/concurrency.
- Performance lift: It comes from sharding-key routing that spreads requests across independent nodes, cutting per-node CPU/IO/lock contention—not from doubling thread/connection counts.
- Fair comparison: Keep the same client concurrency (e.g., `--threads=200`). Size each shard’s pool so it isn’t the bottleneck (e.g., 100–200 per node depending on skew/spikes). Near-2× is realistic only when the sharding key is evenly distributed and SQLs are single-shard; cross-shard/broadcast will lower the gain.
Summary: More Proxy instances (behind LVS or similar) let you fan out more frontend connections and raise end-to-end throughput. More DB shards raise total backend connections while keeping roughly the same per-DB pool, letting you break a single-DB bottleneck on CPU/IO/locks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3696825223
The Proxy doesn’t split or create client threads. Performance gain comes from routing by sharding key to different nodes, where each node executes independently, reducing single-node resource contention.
Connection pool sizing is per data source (node); active connections depend on routing and concurrency, not a fixed “all threads per node.”
- Client threads: remain 6 (or 200 for sysbench); the Proxy only routes/forwards, it doesn’t split threads.
- Routing & parallelism: for sharded writes, each SQL goes to one shard/node based on the sharding key. With even distribution, two nodes each handle roughly half the requests, reducing lock/CPU/IO contention per node, so throughput rises. The lift isn’t from doubling thread count but from splitting work across independent resource pools.
- Proxy/backend connections: Hikari pool config applies per data source; two nodes each have up to 200 connections, actual usage depends on active requests routed there. Sysbench’s 200 concurrency roughly splits under even sharding; it’s not “each node must have 200 active threads.”
- Near-2× gain requires: balanced sharding-key distribution, sufficient front-end concurrency, adequate node resources, and no other bottlenecks (cross-shard/broadcast SQL will reduce gains).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3698428216
Thank you for the detailed explanation. The puzzle has finally come together for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3697669716
**Sorry for the large number of messages — there’s a lot of information in my head, and it’s hard to structure it all at once. If this is inconvenient to read, I can consolidate everything into a single, well-structured message for your convenience. Please let me know if that would be helpful, thank you.**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3697664026
**In short, the setup is as follows:**
**200 sysbench threads**
- **Single**
- 200 frontend connections → up to 200 backend connections to a single database (HikariPool).
- All 200 concurrent requests are handled by one node, which may lead to resource contention.
- **Cluster via Proxy**
- 200 frontend connections to the Proxy.
- Backend connections are created according to the pool configuration:
- With `maxPoolSize = 200` and `minPoolSize = 200`
- The Proxy creates up to 200 backend connections **per node** (400 total for two nodes).
- This provides sufficient connection headroom and avoids connection-pool queuing.
- With even request distribution across shards, the workload is split between nodes, and total throughput can approach **~2× compared to single**.
- With `maxPoolSize = 100` and `minPoolSize = 100`
- The Proxy creates up to 100 backend connections per node (200 total).
- In this case, the cluster’s total parallelism is comparable to single.
- Performance will be roughly the same as single, or lower if requests are not distributed close to 50/50 (queues may appear on the more heavily loaded node).
It is also important to note that **having 400 backend connections does not automatically produce a 2× performance gain**.
The Proxy only creates connection pools on each node; **how many of those connections are actually active** depends on routing and the current workload.
With 200 connections per node, there is simply enough headroom so the connection pool does not become a bottleneck and requests do not wait for a free connection.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3696899399
I want to slightly adjust the overall picture.
As I understand it, there are two types of connections: **frontend** and **backend**. Frontend connections describe how the client connects to the Proxy: for example, with `threads = 200`, 200 connections to the Proxy are created. Then the Proxy internally looks at the configuration where the limits for backend connections are defined. If `maxPoolSize = 200` and `minPoolSize = 200` are set there, the Proxy creates 200 connections to each node. As a result, the load is actually parallelized with 200 connections per node, whereas in the single setup the same 200 connections work against only one database, which makes single roughly two times slower than the cluster.
P.S. If `minPoolSize` is not set, the Proxy may create fewer connections (for example, around 100) and still work fine, but to clearly observe a performance gain, the number of backend connections needs to be comparable to the number of connections in the single setup multipl
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent closed issue #37569: Question about thread parallelization
URL: https://github.com/apache/shardingsphere/issues/37569
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Question about thread parallelization [shardingsphere]
Posted by "makssent (via GitHub)" <gi...@apache.org>.
makssent commented on issue #37569:
URL: https://github.com/apache/shardingsphere/issues/37569#issuecomment-3696855043
Okay, as I understand it, the threads remain the same both for the proxy and for the single setup, just as I initially assumed. Most likely, I simply mixed up connections and threads. Roughly speaking, in sysbench with 200 threads, the test on single will have 200 threads, and on proxy it will also have 200 threads.
What I don’t understand next is what exactly is meant by “even distribution across nodes” and how this is related to the HikariPool configuration. Based on my tests, performance gains appeared only when I explicitly set the connection pool size. The situation was as follows: in the single setup, with `threads = 200` and `HikariPool = 200`, I had 200 connections to a single database, while when working through the Proxy with the same `threads = 200`, but with `HikariPool = 200` on each node, I ended up with 400 connections to the backends in total. In this scenario, requests were indeed sent in parallel to different shards (`ds_0`, `ds_1`), each node processed its own part of the load, and as a result I observed a performance gain close to ×2. Am I correct in understanding that this is exactly what is meant by load distribution?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org