MySQL connections, 1 or more is faster?
#1

Hi,
I just thought about this:
I have my own machine, with a MySQL server.
All my game-mode have only 1 connection-handle (1 MySQL connection I guess).
Do you guys think it would be faster if I would open like 10-15 connections and have different parts of the script use different connections?
Simple question: Would it be faster to have all my SQL requests divided into 10 connections instead of using only 1 connection.

Thank you,
rt-2
Reply
#2

rly wtf, use one connection.
Reply
#3

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
rly wtf, use one connection.
Why?
Reply
#4

If you are using blueG/maddinat0r mysql plugin, it already does that for you (only for threaded queries of course). https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect - connection_pool parameter. Still, due to singlethreaded samp nature, you'll have to parse them one by one. It doesn't make sense to split 1 query into 10 separate ones as the call itself is the heaviest part, but having a pool of separate and distinct queries, running them in parallel is good for you.
Reply
#5

Quote:
Originally Posted by Misiur
Посмотреть сообщение
If you are using blueG/maddinat0r mysql plugin, it already does that for you (only for threaded queries of course). https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect - connection_pool parameter. Still, due to singlethreaded samp nature, you'll have to parse them one by one. It doesn't make sense to split 1 query into 10 separate ones as the call itself is the heaviest part, but having a pool of separate and distinct queries, running them in parallel is good for you.
Thank you,
But What I was thinking is using a single connection-handle for my vehicles, and another for my plants, etc.
The result would be that all queries would be divided in general, that's what I was thinking of.
I don't know if what you meant applies to that?
Reply
#6

Yup, mysql server and database can handle multiple connections to it at once, and that is what connection pool does, there's no waiting for another query to return results. If you mean connecting to multiple databases, then that's another story, and except for very large sites I haven't seen it implemented (even then you still kinda connect to single database, but it goes through load balancers and some other magic).
Reply
#7

Quote:
Originally Posted by blinkpnk
Посмотреть сообщение
Thank you,
But What I was thinking is using a single connection-handle for my vehicles, and another for my plants, etc.
The result would be that all queries would be divided in general, that's what I was thinking of.
I don't know if what you meant applies to that?
Ok so what you say basically is that it will create another connection each query anyway (logicly)?
Reply
#8

Well, basically, it doesn't create a new connection. Imagine MySQL connection as a highway with n number of lanes. And each time you send a threaded query it makes n++, so it doesn't have to wait until the first lane is clear, instead it goes and drives the free lane to the server.

Get it?
Reply
#9

Quote:
Originally Posted by venomlivno8
Посмотреть сообщение
Well, basically, it doesn't create a new connection. Imagine MySQL connection as a highway with n number of lanes. And each time you send a threaded query it makes n++, so it doesn't have to wait until the first lane is clear, instead it goes and drives the free lane to the server.

Get it?
Ok that's what I thought,
Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)