dbTalk Databases Forums  

Using mysql++ with a server.

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Using mysql++ with a server. in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Imperio59
 
Posts: n/a

Default Using mysql++ with a server. - 03-04-2005 , 11:59 PM






Hi,
I'm currently working on a modification for the Half Life 2 engine, one
of the features in this project is that the server will query a master
database on our web server and cross reference player names and IDs to
see if they are suscribers to our "Regulars" program. Long story short,
the game server cannot afford to "freeze" every so often to perform an
SQL query.

I've ran some test apps with mysql++ building with MSVC++ 2003 and the
library it uses for debugging is the multi-threaded library, so I
assumed that mysql++ ran it's code in a seperate thread, but i don't
have... any experience with multi-threading besides some theory in a
recent college course on process handling, so my question is, do i need
to create a separate function that handles all my updating code for the
list of "Regulars" currently on the server and run that as a separate
thread (but then I will have to worry about mutexes and other such
unfamiliar things to me) or is there some way for me to just call an
UpdateDatabase() function of sorts without fear that the query will
"freeze" my server?

Another option was to start up the connection to the database when the
server loads and keep it alive all throughout the duration of a round,
but I think that would be a cheap and wrong way to do it...

Thanks in advance
Imperio59 a.k.a Florian Laplantif


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.6.1 - Release Date: 04/03/2005



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Earl Miles
 
Posts: n/a

Default Re: Using mysql++ with a server. - 03-05-2005 , 12:12 AM






Imperio59 wrote:
Quote:
Another option was to start up the connection to the database when the
server loads and keep it alive all throughout the duration of a round,
but I think that would be a cheap and wrong way to do it...
Believe it or not, this is pretty much the accepted way to do this.
Keeping connections open is not terribly expensive, unless you have too
many of them; in which case, what you really should do is have a server
which holds a connection.

It doesn't sound, to me, like threads will really be your answer. To
properly utilize a thread, you'll need to have some way to pass data
from your main program to your thread, and back, and that runs into fun
locking issues that are well beyond this forum.

Lastly, Warren thinks mysql++ is probably thread-safe, but it can't be
guaranteed. I use mysql++ in a thread on linux, and I seem to be doing
pretty well with it, but I have a very limited usage of it.

At the very least, you have a fun problem on your hands. Good luck
solving it!

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Warren Young
 
Posts: n/a

Default Re: Using mysql++ with a server. - 03-05-2005 , 12:24 AM



Imperio59 wrote:

Quote:
library it uses for debugging is the multi-threaded library, so I
assumed that mysql++ ran it's code in a seperate thread,
No, I chose to set the projects to link MySQL++ against the mulit-thread
CRT libraries for two reasons:

1. It seemed to be most popular. Since Visual C++ requires that you use
the same CRT library for everything linked into a program, this seemed
like the path of least resistance.

2. It gives the _potential_ to use MySQL++ in a threaded program.

MySQL++ does not create its own threads. If you want threads, you have
create and manage them yourself.

Quote:
Another option was to start up the connection to the database when the
server loads and keep it alive all throughout the duration of a round,
but I think that would be a cheap and wrong way to do it...
MySQL database connections aren't expensive in any meaningful sense.
The only possible problem is that you have to have some traffic on the
connection periodically or the server (?) will shut it down.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Warren Young
 
Posts: n/a

Default Re: Using mysql++ with a server. - 03-05-2005 , 12:28 AM



Earl Miles wrote:

Quote:
Warren thinks mysql++ is probably thread-safe,
No, he thinks that with 1.7.30, it is _potentially_ thread-safe on Unixy
systems. It has been thread-safe to exactly the same degree on Windows
systems for quite some time now.

All I have done to attain this potentiality is link against the
thread-safe libraries where available. I have done precisely zilch to
ensure that MySQL++ itself is thread-safe, because I don't use threads
with MySQL++.

Point of fact, I only use threads under extreme duress. There's usually
a better way to handle such problems, in my experience.

In short, it's up to you, the users of threads, to find any bugs that
may be present. I have no interest in doing a thread safety audit.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #5  
Old   
Imperio59
 
Posts: n/a

Default Re: Using mysql++ with a server. - 03-07-2005 , 01:57 PM



My only concern with keeping the connection alive was that if our MOD
gets very popular (and hopefully it will be), it could potentially mean
upwards of 1000 connections on the mysql server open at all times, I
don't know enough about Web Servers and such to know if this is an
extreme load or something a good strong server can handle without any
problems.

There is precedent in the community with the Natural Selection MOD for
HL1 wich did the same thing (fetching a list of suscribers with a mysql
link) and the rumor is that they've had to beef up their server many
times to handle all the stress they were getting, so I guess they must
have been keping the connection alive for the entire duration of the map
round.

I guess i will put it in this way for now, and if there are load issues
with our web servers in the future i will reconsider then, but for now
it sounds like a good solution to me


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.6.3 - Release Date: 07/03/2005



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.