473,750 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parallel interpreter/db problem. transaction didn't fix.

mysql_query("ST ART TRANSACTION", $link2);
$q2=mysql_query ("SELECT pictures.pid AS pid
FROM pictures,counte r
WHERE pictures.pid>co unter.pid
LIMIT 1", $link2);
if ($row2=mysql_fe tch_assoc($q2)) {
mysql_query("UP DATE counter SET pid=$row2[pid]", $link2);
$n=$row2['pid'];
} else { //reached end of table.
mysql_query("UP DATE counter SET pid=1", $link2);
$n=1;
}
mysql_free_resu lt($q2);
mysql_query("CO MMIT", $link2);

the transaction makes no difference in the outcome.
I've even tried locking the tables, but that only results in invalid
resource errors.
when this picture code is called twice in sequence, (2 separate
interpreters, possibly by separate processors), I get the same image. I
shouldn't be getting the same image twice. this is one of those
hair-pulling sessions.

Everything I've tried results either in no pictures at all (picture
placeholders) with both the same sizes due to errors, or with the same
pictures on the same page.

transactions, no transactions, using a counter is out of the question.
I don't understand what's even happening here. the transaction *should* fix
this! Am I missing something
Apr 23 '06 #1
14 1804
>mysql_query("S TART TRANSACTION", $link2);
$q2=mysql_quer y("SELECT pictures.pid AS pid
FROM pictures,counte r
WHERE pictures.pid>co unter.pid
LIMIT 1", $link2);
if ($row2=mysql_fe tch_assoc($q2)) {
mysql_query("UP DATE counter SET pid=$row2[pid]", $link2);
$n=$row2['pid'];
} else { //reached end of table.
mysql_query("UP DATE counter SET pid=1", $link2);
$n=1;
}
mysql_free_res ult($q2);
mysql_query("C OMMIT", $link2);
Check to see whether your queries WORK. If they do not work,
print out the query and the value of mysql_error(). (For actual
production code, log it somewhere the user won't see it).
the transaction makes no difference in the outcome.
The transaction may be counterproducti ve. For certain applications,
having uncommitted changes be NOT visible to other connections until
they are committed can bite you big time. One example of this is
the "last modified" timestamp being used to identify recently changed
stuff, to actually make the changes in the real world (e.g. create
mailboxes). When it can take a long time to commit a transaction,
the "last modified" date can go from months old to hours old without
ever having been only a few minutes old, fooling provisioning software
trying to see all the changes and not miss any.
I've even tried locking the tables, but that only results in invalid
resource errors.
Then find out why your query didn't work, and fix it (print
mysql_error() for the failing query). You need to lock ALL the
tables you're going to use, and if you use aliases, you may have
to lock them under the name of the alias.
when this picture code is called twice in sequence, (2 separate
interpreters , possibly by separate processors), I get the same image. I
shouldn't be getting the same image twice. this is one of those
hair-pulling sessions.

Everything I've tried results either in no pictures at all (picture
placeholders )
Please explain how that can happen in terms of the generated HTML.
Are you generating numbers for which there is no image file?
with both the same sizes due to errors, or with the same
pictures on the same page.

transactions , no transactions, using a counter is out of the question.
I don't understand what's even happening here. the transaction *should* fix
this! Am I missing something


Gordon L. Burditt
Apr 23 '06 #2

"Gordon Burditt" <go***********@ burditt.org> wrote in message
news:12******** *****@corp.supe rnews.com...
mysql_query("S TART TRANSACTION", $link2);
$q2=mysql_que ry("SELECT pictures.pid AS pid
FROM pictures,counte r
WHERE pictures.pid>co unter.pid
LIMIT 1", $link2);
if ($row2=mysql_fe tch_assoc($q2)) {
mysql_query("UP DATE counter SET pid=$row2[pid]", $link2);
$n=$row2['pid'];
} else { //reached end of table.
mysql_query("UP DATE counter SET pid=1", $link2);
$n=1;
}
mysql_free_re sult($q2);
mysql_query(" COMMIT", $link2);
Check to see whether your queries WORK. If they do not work,
print out the query and the value of mysql_error(). (For actual
production code, log it somewhere the user won't see it).


well, adding the transaction didn't affect *anything*. so I'm thinking
wrong somewhere.
my guess was that instance B and instance A had both read the same value at
nearly the same time, UPDATEd with the same value as a result. a race
condition. I had *thought* a transaction would fix that, but obviously
there's something about transactions I don't understand. I couldn't get
table locking (counter READ) to work - it just gave me invalid resource
errors down the line on my queries. I've never used table locking in PHP
code before.
If I could get table locking going, maybe that would be the fix to my
problem.

the transaction makes no difference in the outcome.


The transaction may be counterproducti ve. For certain applications,
having uncommitted changes be NOT visible to other connections until
they are committed can bite you big time. One example of this is
the "last modified" timestamp being used to identify recently changed
stuff, to actually make the changes in the real world (e.g. create
mailboxes). When it can take a long time to commit a transaction,
the "last modified" date can go from months old to hours old without
ever having been only a few minutes old, fooling provisioning software
trying to see all the changes and not miss any.

Good to know. as far as I can tell, the updates are occurring.
I've even tried locking the tables, but that only results in invalid
resource errors.


Then find out why your query didn't work, and fix it (print
mysql_error() for the failing query). You need to lock ALL the
tables you're going to use, and if you use aliases, you may have
to lock them under the name of the alias.
when this picture code is called twice in sequence, (2 separate
interpreter s, possibly by separate processors), I get the same image. I
shouldn't be getting the same image twice. this is one of those
hair-pulling sessions.

Everything I've tried results either in no pictures at all (picture
placeholder s)


Please explain how that can happen in terms of the generated HTML.
Are you generating numbers for which there is no image file?
with both the same sizes due to errors, or with the same
pictures on the same page.

transaction s, no transactions, using a counter is out of the question.
I don't understand what's even happening here. the transaction *should*
fix
this! Am I missing something


Gordon L. Burditt

Apr 24 '06 #3

"Jim Michaels" <NO************ ***@yahoo.com> wrote in message
news:4s******** ************@co mcast.com...

"Gordon Burditt" <go***********@ burditt.org> wrote in message
news:12******** *****@corp.supe rnews.com...
>mysql_query("S TART TRANSACTION", $link2);
$q2=mysql_qu ery("SELECT pictures.pid AS pid
FROM pictures,counte r
WHERE pictures.pid>co unter.pid
LIMIT 1", $link2);
if ($row2=mysql_fe tch_assoc($q2)) {
mysql_query("UP DATE counter SET pid=$row2[pid]", $link2);
$n=$row2['pid'];
} else { //reached end of table.
mysql_query("UP DATE counter SET pid=1", $link2);
$n=1;
}
mysql_free_r esult($q2);
mysql_query( "COMMIT", $link2);
Check to see whether your queries WORK. If they do not work,
print out the query and the value of mysql_error(). (For actual
production code, log it somewhere the user won't see it).


well, adding the transaction didn't affect *anything*. so I'm thinking
wrong somewhere.
my guess was that instance B and instance A had both read the same value
at nearly the same time, UPDATEd with the same value as a result. a race
condition. I had *thought* a transaction would fix that, but obviously
there's something about transactions I don't understand. I couldn't get
table locking (counter READ) to work - it just gave me invalid resource
errors down the line on my queries. I've never used table locking in PHP
code before.
If I could get table locking going, maybe that would be the fix to my
problem.


nope. table locking didn't work either. :-( i'm out of ideas. PHP has no
access to the UNIX system-level-like getuuid() function that I can use in
place of a random number generator. that would have been perfect.

There must be some way of doing a wrapping counter that works like a web
counter (exclusive access at transaction time).


the transaction makes no difference in the outcome.


The transaction may be counterproducti ve. For certain applications,
having uncommitted changes be NOT visible to other connections until
they are committed can bite you big time. One example of this is
the "last modified" timestamp being used to identify recently changed
stuff, to actually make the changes in the real world (e.g. create
mailboxes). When it can take a long time to commit a transaction,
the "last modified" date can go from months old to hours old without
ever having been only a few minutes old, fooling provisioning software
trying to see all the changes and not miss any.

Good to know. as far as I can tell, the updates are occurring.
I've even tried locking the tables, but that only results in invalid
resource errors.


Then find out why your query didn't work, and fix it (print
mysql_error() for the failing query). You need to lock ALL the
tables you're going to use, and if you use aliases, you may have
to lock them under the name of the alias.
when this picture code is called twice in sequence, (2 separate
interpreters , possibly by separate processors), I get the same image. I
shouldn't be getting the same image twice. this is one of those
hair-pulling sessions.

Everything I've tried results either in no pictures at all (picture
placeholders )


Please explain how that can happen in terms of the generated HTML.
Are you generating numbers for which there is no image file?
with both the same sizes due to errors, or with the same
pictures on the same page.

transactions , no transactions, using a counter is out of the question.
I don't understand what's even happening here. the transaction *should*
fix
this! Am I missing something


Gordon L. Burditt


Apr 24 '06 #4

"Jim Michaels" <NO************ ***@yahoo.com> wrote in message
news:4s******** ************@co mcast.com...

"Gordon Burditt" <go***********@ burditt.org> wrote in message
news:12******** *****@corp.supe rnews.com...
>mysql_query("S TART TRANSACTION", $link2);
$q2=mysql_qu ery("SELECT pictures.pid AS pid
FROM pictures,counte r
WHERE pictures.pid>co unter.pid
LIMIT 1", $link2);
if ($row2=mysql_fe tch_assoc($q2)) {
mysql_query("UP DATE counter SET pid=$row2[pid]", $link2);
$n=$row2['pid'];
} else { //reached end of table.
mysql_query("UP DATE counter SET pid=1", $link2);
$n=1;
}
mysql_free_r esult($q2);
mysql_query( "COMMIT", $link2);
Check to see whether your queries WORK. If they do not work,
print out the query and the value of mysql_error(). (For actual
production code, log it somewhere the user won't see it).


well, adding the transaction didn't affect *anything*. so I'm thinking
wrong somewhere.
my guess was that instance B and instance A had both read the same value
at nearly the same time, UPDATEd with the same value as a result. a race
condition. I had *thought* a transaction would fix that, but obviously
there's something about transactions I don't understand. I couldn't get
table locking (counter READ) to work - it just gave me invalid resource
errors down the line on my queries. I've never used table locking in PHP
code before.
If I could get table locking going, maybe that would be the fix to my
problem.


Oh yeah - I forgot. The PC's Timer (clock) is normally set to interrupt
18.2 times per second (18.2Hz). This is much slower than millisecond
resolution than PHP claims. Unless Linux sets the Timer to something else,
(unix normally wants something around 100Hz I think), the nice fast XEON
server boxes we have today with up to 8MB cache, combined with web server
cacheing, may be contributing to my problem. But then I'm guessing.
I guess I should stop yapping & learn.

My biggest question is what works. if I delete am image from the database,
that leaves a hole in it. I can't use a plain counter (unless I include
code to continually bump the counter until it reaches a valid pid valie)
that's why the WHERE pid>$currentpid .
I may have to try the counter method. UPDATE blah SET counter=counter +1
seems to be more atomic/exclusive (?) than my other methods. what's going
to bite me is when I need to wrap the counter back to 1 or skip to the next
valid value. I don't know how to lock other processes out of the table.
ideas?
would be nice if I could have a random number generator that worked.

I just realized how I can generate an image without having to turn the
entire PHP file into a monolith image generator.

and I can use the random number generator too.
it works!

If I have to use the other method, I am still curious how to make things
work, because I have an existing codebase that needs to be fixed, that sends
content-type headers.

the transaction makes no difference in the outcome.


The transaction may be counterproducti ve. For certain applications,
having uncommitted changes be NOT visible to other connections until
they are committed can bite you big time. One example of this is
the "last modified" timestamp being used to identify recently changed
stuff, to actually make the changes in the real world (e.g. create
mailboxes). When it can take a long time to commit a transaction,
the "last modified" date can go from months old to hours old without
ever having been only a few minutes old, fooling provisioning software
trying to see all the changes and not miss any.

Good to know. as far as I can tell, the updates are occurring.
I've even tried locking the tables, but that only results in invalid
resource errors.


Then find out why your query didn't work, and fix it (print
mysql_error() for the failing query). You need to lock ALL the
tables you're going to use, and if you use aliases, you may have
to lock them under the name of the alias.
when this picture code is called twice in sequence, (2 separate
interpreters , possibly by separate processors), I get the same image. I
shouldn't be getting the same image twice. this is one of those
hair-pulling sessions.

Everything I've tried results either in no pictures at all (picture
placeholders )


Please explain how that can happen in terms of the generated HTML.
Are you generating numbers for which there is no image file?
with both the same sizes due to errors, or with the same
pictures on the same page.

transactions , no transactions, using a counter is out of the question.
I don't understand what's even happening here. the transaction *should*
fix
this! Am I missing something


Gordon L. Burditt


Apr 24 '06 #5
> nope. table locking didn't work either. :-( i'm out of ideas. PHP has no
access to the UNIX system-level-like getuuid() function that I can use in
place of a random number generator. that would have been perfect.


Second time today I've suggest getmypid().

Apr 24 '06 #6
Jim Michaels wrote:


well, adding the transaction didn't affect *anything*. so I'm thinking
wrong somewhere.
my guess was that instance B and instance A had both read the same value at
nearly the same time, UPDATEd with the same value as a result. a race
condition. I had *thought* a transaction would fix that, but obviously
there's something about transactions I don't understand. I couldn't get
table locking (counter READ) to work - it just gave me invalid resource
errors down the line on my queries. I've never used table locking in PHP
code before.
If I could get table locking going, maybe that would be the fix to my
problem.


Invalid resource errors should never occur. They mean you're getting an error
on your queries - and not checking for them.

Always check the results of MySQL queries! NEVER ASSUME THEY WORK!

And when you do check the result, what do you get?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 24 '06 #7

"fletch" <ri************ ****@googlemail .com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
nope. table locking didn't work either. :-( i'm out of ideas. PHP has
no
access to the UNIX system-level-like getuuid() function that I can use in
place of a random number generator. that would have been perfect.


Second time today I've suggest getmypid().


used getmypid(). I get (surprisingly) the same pictures on the page. I
don't understand this.

mt_srand(make_s eed()+getmypid( ));

Was what I used. make_seed() returns a float. Why PHP manual recommended
such a function I am not sure.
maybe I should just use getmypid() alone? Is that what you're trying to
say?
Apr 25 '06 #8

"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:p_******** *************** *******@comcast .com...
Jim Michaels wrote:


well, adding the transaction didn't affect *anything*. so I'm thinking
wrong somewhere.
my guess was that instance B and instance A had both read the same value
at nearly the same time, UPDATEd with the same value as a result. a race
condition. I had *thought* a transaction would fix that, but obviously
there's something about transactions I don't understand. I couldn't get
table locking (counter READ) to work - it just gave me invalid resource
errors down the line on my queries. I've never used table locking in PHP
code before.
If I could get table locking going, maybe that would be the fix to my
problem.

Invalid resource errors should never occur. They mean you're getting an
error on your queries - and not checking for them.

Always check the results of MySQL queries! NEVER ASSUME THEY WORK!

And when you do check the result, what do you get?


checked the server error logs, figured out how to find & fix the errors and
actually get an error message. turned out the tables I had locked for READ
and later were trying to UPDATE (write) was the cause of the error, so I
needed a write lock. so I changed the LOCK TABLES to a write lock.
Then I got another error stating that the other tables down the line needed
to be locked too. (ugh) so I did. then things were fixed.
Sort of.
images were still duplicated. (not again!)
lock tables didn't do it for me. the only thing I can figure is that
*maybe* the write lock doesn't prevent reads to the table and I still have a
race condition.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Apr 25 '06 #9

"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:p_******** *************** *******@comcast .com...
Jim Michaels wrote:


well, adding the transaction didn't affect *anything*. so I'm thinking
wrong somewhere.
my guess was that instance B and instance A had both read the same value
at nearly the same time, UPDATEd with the same value as a result. a race
condition. I had *thought* a transaction would fix that, but obviously
there's something about transactions I don't understand. I couldn't get
table locking (counter READ) to work - it just gave me invalid resource
errors down the line on my queries. I've never used table locking in PHP
code before.
If I could get table locking going, maybe that would be the fix to my
problem.

Invalid resource errors should never occur. They mean you're getting an
error on your queries - and not checking for them.

Always check the results of MySQL queries! NEVER ASSUME THEY WORK!

And when you do check the result, what do you get?


Do you suppose my transaction tryout didn't work because I had a SELECT
directly after the COMMIT on the same connection? Should everything be
lumped together for everything to work properly? I am new to transactions.


--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Apr 25 '06 #10

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

Similar topics

0
1746
by: Markus Franz | last post by:
Hi. I have a difficult problem: An array contains several different URLs. I want to load these websites in parallel by using a HTTP-Request. How can I do this in PHP? Up to now I did this with an external Python script because Python offers process control functions. But in PHP only exist restricted possibilities for using threads / processes.
2
3410
by: Michael Schmitt | last post by:
Hello. What is the usual way for running functions in parallel on a multiple-processor machine. Actually I want to run a single computationally expensive function with different parameter sets. Running the functions in different threads doesn't seem to work, because of the global interpreter lock. Would it help to fork processes, which run the single function with a given parameter set? Is there any simple way, how this forked worker...
0
1890
by: Yuancai \(Charlie\) Ye | last post by:
Hi, All: I am happy to annouce that we have formally released our latest SocketPro version 4 at www.udaparts.com, an advanced remoting framework written from batching/queue, asynchrony and parallel computation. Key Benefits of SocketPro: Super performance and scalability It is a guarantee that SocketPro based client-server applications
7
4232
by: Steven D.Arnold | last post by:
How good is Postgres' performance for massive simultaneous insertions into the same heavily-indexed table? Are there any studies or benchmarks I can look at for that? I understand Postgres uses MVCC rather than conventional locking, which makes it easier to do parallel inserts. In my environment, I will have so many inserts that it is unworkable to have one machine do all the inserting -- it would max out the CPU of even a very...
5
1676
by: MIchael Ullrich | last post by:
Hi, actually I have a childform, which runs a self-written script interpreter (runs aprox. 1 min). I want to create more child-forms and I want to have the interpreters run parallel. Right now only the interpreter of the last created form is running until it is finished and then the other ones are continuing. How can I make parallel working child-forms
8
2815
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 this is the section of code. if (isset($row4)) { if (isset($row5)) { //answer given? if ($row4==$row5) {
43
4317
by: parallelpython | last post by:
Has anybody tried to run parallel python applications? It appears that if your application is computation-bound using 'thread' or 'threading' modules will not get you any speedup. That is because python interpreter uses GIL(Global Interpreter Lock) for internal bookkeeping. The later allows only one python byte-code instruction to be executed at a time even if you have a multiprocessor computer. To overcome this limitation, I've created...
6
2035
by: Rafael Almeida | last post by:
Hello, I'm studying compilers now on my university and I can't quite understand one thing about the python interpreter. Why is its input a binary file (pyc)? The LOAD_CONST opcode is 100 (dec) and STORE_FAST's is 125 (dec). The translation of the following code: foo.py: x = 10
6
12152
by: Abandoned | last post by:
Hi.. I use the threading module for the fast operation. But i have some problems.. This is my code sample: ================= conn = psycopg2.connect(user='postgres',password='postgres',database='postgres') cursor = conn.cursor() class paralel(Thread): def __init__ (self, veriler, sayii):
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9394
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.