Unix Technical Forum

[Q] event for client?

This is a discussion on [Q] event for client? within the MySQL General forum forums, part of the MySQL category; --> SQL Hello! Is there any way to inform mysql client application about changing in the some table. One process ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:37 AM
Andrey Kotrekhov
 
Posts: n/a
Default [Q] event for client?

SQL
Hello!

Is there any way to inform mysql client application about changing in
the some table.

One process puts periodically record into the table.
Second process waits new records.
It is very expensive way to do SELECT from this table each second.
Is there any other right way to inform second process?

Best regards.
_______________________________________
Andrey Kotrekhov kota@alkar.net
ISP Alkar Teleport
ΤΕΜ. +380 562 34-00-44
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:37 AM
Baron Schwartz
 
Posts: n/a
Default Re: [Q] event for client?

Hi Andrey.

Andrey Kotrekhov wrote:
> SQL
> Hello!
>
> Is there any way to inform mysql client application about changing in
> the some table.
>
> One process puts periodically record into the table.
> Second process waits new records.
> It is very expensive way to do SELECT from this table each second.
> Is there any other right way to inform second process?


I was waiting to see if anyone else had any ideas, because I don't think my ideas are
very good. I should say that I think this is generally a hard problem to solve with
generic SQL, but I think some systems do support their own extensions to provide
signalling or notification.

In MySQL, the two things I can think of are:

1) make the polling more efficient. Instead of polling the table you're watching, have
the inserting process set a flag in another, smaller table, and poll that table.
Another thing you can do to make polling more efficient, when it is necessary, is use a
variable wait time. Exponential or Fibonacci has worked well for me. For more on
this, see
http://www.xaprb.com/blog/2006/05/04...ling-interval/

2) Take advantage of things that use semaphores under the covers. The most obvious one
for me is a string lock with GET_LOCK(). The waiting process and the polling process
could get and release the lock to signal each other. Be careful though, as if you use
more than one lock, there is a potential for deadlock, and if you don't there is a
potential for race conditions.

I have not implemented this myself, and think I would probably write something buggy on
my first attempt, so these are just crude ideas.

Cheers
Baron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:37 AM
Ulrich Staudinger
 
Posts: n/a
Default Re: [Q] event for client?

Hi Andrey,
> Andrey Kotrekhov wrote:
>> SQL
>> Hello!
>>
>> Is there any way to inform mysql client application about changing in
>> the some table.
>>
>> One process puts periodically record into the table.
>> Second process waits new records.
>> It is very expensive way to do SELECT from this table each second.
>> Is there any other right way to inform second process?

>


Have you had a look at streamsql already [ http://www.streamsql.org ] ?
It does precisely what you want, it's just not mysql and therefore of
course not that well suited for a couple of other db aspects.

Cheers,
Ulrich.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 06:37 AM
Michael Dykman
 
Posts: n/a
Default Re: [Q] event for client?

On 6/13/07, Ulrich Staudinger <us@activestocks.de> wrote:
> Hi Andrey,
> > Andrey Kotrekhov wrote:
> >> SQL
> >> Hello!
> >>
> >> Is there any way to inform mysql client application about changing in
> >> the some table.


There are triggers of course which could be used to track any specific
DML event. Depending on what the second process is supposed to do,
one might implement that second process as a server-side procedure.
Failing that, the trigger event *could* be made to launch a system
script, not that it is a course I would recommend lightly. None of
these will signal the client directly, as per mysql protocol, but an
external signal could be brought to bear.

--
- michael dykman
- mdykman@gmail.com

- All models are wrong. Some models are useful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 06:40 AM
Andrey Kotrekhov
 
Posts: n/a
Default Re: [Q] event for client?

Hi!
Baron Schwartz wrote:

The situation is more complicated.
I have 2 servers and ring replication between them.
On 1 server there is a process which cashes some data from DB (this
decrease number of queries very match and increase performance).
But sometimes there are some modification of data on 2-d server. Changes
go to the 1-st server by replication.
And only then replication of this changes is done the cashes of data
must be updated
That is why I need the condition of changing some tables on 1-st table.

> Hi Andrey.
>
> Andrey Kotrekhov wrote:
>
>> SQL
>> Hello!
>>
>> Is there any way to inform mysql client application about changing in
>> the some table.
>>
>> One process puts periodically record into the table.
>> Second process waits new records.
>> It is very expensive way to do SELECT from this table each second.
>> Is there any other right way to inform second process?

>
>
> I was waiting to see if anyone else had any ideas, because I don't
> think my ideas are very good. I should say that I think this is
> generally a hard problem to solve with generic SQL, but I think some
> systems do support their own extensions to provide signalling or
> notification.
>
> In MySQL, the two things I can think of are:
>
> 1) make the polling more efficient. Instead of polling the table
> you're watching, have the inserting process set a flag in another,
> smaller table, and poll that table. Another thing you can do to make
> polling more efficient, when it is necessary, is use a variable wait
> time. Exponential or Fibonacci has worked well for me. For more on
> this, see
> http://www.xaprb.com/blog/2006/05/04...ling-interval/
>
>
> 2) Take advantage of things that use semaphores under the covers. The
> most obvious one for me is a string lock with GET_LOCK(). The waiting
> process and the polling process could get and release the lock to
> signal each other. Be careful though, as if you use more than one
> lock, there is a potential for deadlock, and if you don't there is a
> potential for race conditions.
>
> I have not implemented this myself, and think I would probably write
> something buggy on my first attempt, so these are just crude ideas.
>
> Cheers
> Baron




--
Andrey Kotrekhov kota@alkar.net


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:24 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com