473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Xml-Rpc + Mysql.NET = Threading problem

Hello all,

I come to you to getting help for managing multi threading and database connection.

My project use Xml-Rpc to receive messages, so each call come from a different
thread.
Incoming calls are executing SQL on a MysqlConnection.
MysqlConnection does not like when concurents calls appends.

For a fast and dirty solution, I've put a Monitor() at messages arrived.
But I would like to finally got a nicer solution.

What do you think about the architecture I should make ?

Should I create and manage a Pool of MysqlConnection and only locking when pool
is fully occuped ?

Do you know already made solutions for that case ?

Thanks a lot for you comments and ideas,
cyrille.

PS: Before I put the ugly Monitor, I got some errors like :

Exception: Connection must be valid and open. StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )

Exception: Expected prepared statement marker. StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql, String[] parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()
Feb 10 '06 #1
11 2119
what's wrong with the Monitor?

Anyway it's very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connection on
demand.
In fact SqlConnection (for SqlServer), does it for you under the hood.

Otherwise you could open a new connection for each incoming message..

One thing you should NOT do is use the same connection at the same time in
different thread.

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:up**************@TK2MSFTNGP11.phx.gbl...
Hello all,

I come to you to getting help for managing multi threading and database
connection.

My project use Xml-Rpc to receive messages, so each call come from a
different thread.
Incoming calls are executing SQL on a MysqlConnection.
MysqlConnection does not like when concurents calls appends.

For a fast and dirty solution, I've put a Monitor() at messages arrived.
But I would like to finally got a nicer solution.

What do you think about the architecture I should make ?

Should I create and manage a Pool of MysqlConnection and only locking when
pool is fully occuped ?

Do you know already made solutions for that case ?

Thanks a lot for you comments and ideas,
cyrille.

PS: Before I put the ugly Monitor, I got some errors like :

Exception: Connection must be valid and open. StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior
behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )

Exception: Expected prepared statement marker. StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql, String[]
parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()

Feb 11 '06 #2
Hi Lloyd,

Lloyd Dupont a écrit :
what's wrong with the Monitor?
I loos multi-threading processing of incoming messages.
Anyway it's very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connectionon
demand.
In fact SqlConnection (for SqlServer), does it for you under the hood.
That's Great.
I've to find or write a connections pool for MySqlConnection ...
Perhaps someone already done it ?
Otherwise you could open a new connection for each incoming message..
I think it will be to heavy.
One thing you should NOT do is use the same connection at the same timein
different thread.
Thanks for your advise. I'll be care ;o)

Thanks a lot for your councils.
Regards,
cyrille.

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:up**************@TK2MSFTNGP11.phx.gbl...
Hello all,

I come to you to getting help for managing multi threading and database
connection.

My project use Xml-Rpc to receive messages, so each call come from a
different thread.
Incoming calls are executing SQL on a MysqlConnection.
MysqlConnection does not like when concurents calls appends.

For a fast and dirty solution, I've put a Monitor() at messages arrived.
But I would like to finally got a nicer solution.

What do you think about the architecture I should make ?

Should I create and manage a Pool of MysqlConnection and only locking when
pool is fully occuped ?

Do you know already made solutions for that case ?

Thanks a lot for you comments and ideas,
cyrille.

PS: Before I put the ugly Monitor, I got some errors like :

Exception: Connection must be valid and open. StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior
behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )

Exception: Expected prepared statement marker. StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Prepare(String sql, String[]
parmNames)
at MySql.Data.MySqlClient.MySqlCommand.Prepare()




Feb 11 '06 #3
Lloyd Dupont a écrit :
Hi Cyrille37
what's wrong with the Monitor? I loos multi-threading processing of incoming messages.

err.... could you reword this sentence?
I don't manage to guess its meaning....


Sorry for my bad english. I use my extra ball to try again :

With Monitor() at messages arriving, I lose the advantage of multi-threading.

Is that more readable ?
;o)
I have something like that (as an attached document of this answer).
Well it was a useless peace of code as SqlConnection already use a
connection pool under the hood.
But if you replace all the SqlConnection stuff by MySqlConnection it will
suddenly start to make sense!


THANKS A LOT !!!

Ok, I'll try it this afternoon.

<;oP> I hope you've make a non buggy code </;oP>

I give you a report after tests...

Cheers,
cyrille

Feb 11 '06 #4
>>> I loos multi-threading processing of incoming messages.
err.... could you reword this sentence?
I don't manage to guess its meaning....
Sorry for my bad english. I use my extra ball to try again :

With Monitor() at messages arriving, I lose the advantage of
multi-threading.

Is that more readable ?
;o)

Oh.. I see... right!
I have something like that (as an attached document of this answer).
Well it was a useless peace of code as SqlConnection already use a
connection pool under the hood.
But if you replace all the SqlConnection stuff by MySqlConnection it will
suddenly start to make sense!


THANKS A LOT !!!

Ok, I'll try it this afternoon.

<;oP> I hope you've make a non buggy code </;oP>

I hope too! ;-)

I give you a report after tests...

Cheers,

Yep, do tell me! Hopes it will work great!

Feb 11 '06 #5
Lloyd Dupont a écrit :
what's wrong with the Monitor?

Anyway it's very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connectionon
demand.


What about the Prepared Statements ?

I think they are associated with a SqlConnection.
So If I create some prepared statements they will stay associated with the
connection but I could not use them if Pool give me another connection ...

I'm not clear because I could not imagine how Prepared Statement will be managed
when using a ConnectionPool.

What do you think about that ??

thanks
cyrille.
Feb 11 '06 #6
Lloyd Dupont a écrit :
I have something like that (as an attached document of this answer).
Well it was a useless peace of code as SqlConnection already use a
connection pool under the hood.
But if you replace all the SqlConnection stuff by MySqlConnection it will
suddenly start to make sense!


Yeah !
Your code works fine.

I've just made one change that do not close connections when freeing them, to
avoid the open/close overload.
Connections will be closed by MySqlConnection.Dispose() in MySql.Data.

Another stuff appends to me. While reading the source code of MySql.Data to be
shure connections will be closed, I found that there is already a Connection
Pool in the connector... But I did not know because the documentation does not
talk about...

I don't know if I still need to use the DBConnectionPool ...
By the way, it was fun to test your code ;oP

Cyrille.
Feb 11 '06 #7
# Cyrille37 # a écrit :
Lloyd Dupont a écrit :
I have something like that (as an attached document of this answer).
Well it was a useless peace of code as SqlConnection already use a
connection pool under the hood.
But if you replace all the SqlConnection stuff by MySqlConnection it
will suddenly start to make sense!


Yeah !
Your code works fine.

I've just made one change that do not close connections when freeing
them, to avoid the open/close overload.
Connections will be closed by MySqlConnection.Dispose() in MySql.Data.

Another stuff appends to me. While reading the source code of MySql.Data
to be shure connections will be closed, I found that there is already a
Connection Pool in the connector... But I did not know because the
documentation does not talk about...

I don't know if I still need to use the DBConnectionPool ...
By the way, it was fun to test your code ;oP


I did some stress tests with the DBConnectionPool and without it.

Result are very very faster with DBConnectionPool (my version without Closing).

Cyrille
Feb 11 '06 #8
>> I don't know if I still need to use the DBConnectionPool ...
By the way, it was fun to test your code ;oP


I did some stress tests with the DBConnectionPool and without it.

Result are very very faster with DBConnectionPool (my version without
Closing).


Good!
I guess you'll keep using it! ;-)
Feb 11 '06 #9
I would say, don't reuse them.
Create them on demand each time.
Not only it will make easier to maintain/use/understand, but I dont believe
there is that much to gain by trying to reuse them....

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Lloyd Dupont a écrit :
what's wrong with the Monitor?

Anyway it's very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connection on
demand.


What about the Prepared Statements ?

I think they are associated with a SqlConnection.
So If I create some prepared statements they will stay associated with the
connection but I could not use them if Pool give me another connection ...

I'm not clear because I could not imagine how Prepared Statement will be
managed
when using a ConnectionPool.

What do you think about that ??

thanks
cyrille.
Feb 11 '06 #10
Lloyd Dupont a écrit :
I would say, don't reuse them.
Create them on demand each time.
Not only it will make easier to maintain/use/understand, but I dont believe
there is that much to gain by trying to reuse them....
Hello Lloyd,

I think to reuse prepared statements for queries that are used very often.
In my project, there are about 50 to 100 clients and they are asking manytimes
for the same data.
For logged in, to get list of connected users, to get some layout information
and so on.

I think prepared statements are stored by the sql engine to be ready to replay
them. But they are associated with a connection...
So, perhaps for such needs I've to use a special connection ...

By the way, it's only a performance problem.

Thanks for the talk and for your code.
May I put your code on my wiki, with your name of course ?

cyrille.

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Lloyd Dupont a écrit :
what's wrong with the Monitor?

Anyway it's very typical and advised to have a connection pool which (the
pool) as a properly synchronized access and return a private connection on
demand.


What about the Prepared Statements ?

I think they are associated with a SqlConnection.
So If I create some prepared statements they will stay associated with the
connection but I could not use them if Pool give me another connection ...

I'm not clear because I could not imagine how Prepared Statement will be
managed
when using a ConnectionPool.

What do you think about that ??

thanks
cyrille.



Feb 12 '06 #11
> Thanks for the talk and for your code.
May I put your code on my wiki, with your name of course ?

You're more than welcome ;-)
Feb 12 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Robert J Egan | last post by:
Hi i'm trying to search a remote website page. The form returns xml information, though the page extension is missing. I retrieve the information and write it to the screen. So far so good -...
1
by: felipe_azv | last post by:
a got this code in asp to construct a xml , to export it to a url this is de asp code: <% SQL = "Select * from User where CodeUser in ("& request.form("C1" &")" set rs =...
0
by: MarionEll | last post by:
Premier XML Industry Event Slated for Dec. 7-12 in Philadelphia; Presenters Include Adobe, BEA, Microsoft, IBM, Sun, Hewlett-Packard, Oracle Alexandria, Va. Sept. 30, 2003 - IDEAlliance, a...
6
by: yzzzzz | last post by:
Hi, In which cases is the <?xml version="1.0" encoding="UTF-8"?> processing instruction required at the beginning of an XML document, for the document to be valid? e.g. does it depend on the...
0
by: Stylus Studio | last post by:
World's Most Advanced XML Schema Editor Adds Support for IBM AlphaWorks XML Schema Quality Checker to Improve XML Schema Style and Quality BEDFORD, MA -- 09/13/2005 -- Stylus Studio...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
0
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
9
by: Lie | last post by:
Why this generates AttributeError, then not? Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most...
0
by: Jacker | last post by:
Xpress Author for MS Word XML Documents In.vision Research empowers knowledge workers to create complex XML documents in Microsoft Word (2000-2003) with a normal Word experience. Deploy XML...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.