MYSQL performance issue

MYSQL performance issue

am 06.03.2007 14:45:54 von kanna

Hi,
The following prg keeps cpu usage as 79% always .When i kill/stop the
prg,then cpu comes down.

main()
{
//code for mysql conn
while(1)
mysql_real_query (&mysqlcon, "SET CHARACTER SET 'utf8';", 25);
}

What might be the reason? Wil it be any config issues?

Regards,
sathis

Re: MYSQL performance issue

am 06.03.2007 20:28:36 von Aggro

kanna wrote:
> Hi,
> The following prg keeps cpu usage as 79% always .When i kill/stop the
> prg,then cpu comes down.
>
> main()
> {
> //code for mysql conn
> while(1)
> mysql_real_query (&mysqlcon, "SET CHARACTER SET 'utf8';", 25);
> }
>
> What might be the reason?

What do you expect the cpu usage to be when you call a function in a
loop that never ends?

Re: MYSQL performance issue

am 07.03.2007 10:11:40 von kanna

On Mar 6, 2:28 pm, Aggro wrote:
> kanna wrote:
> > Hi,
> > The following prg keeps cpu usage as 79% always .When i kill/stop the
> > prg,then cpu comes down.
>
> > main()
> > {
> > //code for mysql conn
> > while(1)
> > mysql_real_query (&mysqlcon, "SET CHARACTER SET 'utf8';", 25);
> > }
>
> > What might be the reason?
>
> What do you expect the cpu usage to be when you call a function in a
> loop that never ends?

I undertand that cpu usage wil go up for the above prg.
But cld nt understnad, why it goes very high.

Re: MYSQL performance issue

am 13.03.2007 00:05:57 von Aggro

kanna wrote:

>> What do you expect the cpu usage to be when you call a function in a
>> loop that never ends?
>
> I undertand that cpu usage wil go up for the above prg.
> But cld nt understnad, why it goes very high.

Ok, try this simple example. Raise your hand as quicly as you can and
then lower it as quicly as you can. Now repeat this in endless loop as
fast as you can.

Rasing and lowering your hand is the function. If you repeat this
function in an endless loop without any rest, you should soon find out
that your cpu is turning pretty hot.

If you want to have an endless loop (which is very rare that people
actually want that, unless they don't know what they are doing), you
could add a small rest ( usually done with sleep()-function, but depends
on the programming language ) between the function calls. This would
lower the cpu usage percent dramatically.