As some of you may know and some of you may not know... I had some troubles with ADS Local Server and simultaneous requests which were opening and manipulating tables...
this is the topic I created to ask for some help:
viewtopic.php?f=5&t=112
But I decided to create another topic, to give you some more precise information about the real problem.
When multiple users were sendind requests to my webservice, some of them were opening tables (sometimes different tables, sometimes the same table) at the exact same time, and for some unknown reason it was crashing apache with an ADS error.
Ok... we are talking about ADS Local Server, so can assume that there are some limitations about concurrency and connections managements. So what I did to solve this problem was creating a simple flag control via MySQL, like that:
Código: Seleccionar todo
lOpen:=.T.
oBDFlag:= TMySQl():New("MARIA","localhost","uset","psw","schema",3306)
caliasflag:= "ALIAS01"
nTime:=Seconds()
DO WHILE lOpen .AND. (Seconds()-nTime) < 30
oQry:=NIL
oQry:=oBDFlag:Query("SELECT data, cflag, time FROM flag WHERE data='PARAM01' ",{Trans(Dtos(Date()),"@R 9999-99-99")})
IF oQry = NIL .OR. oQry:Count()<=0
IF (nT:=oBDFlag:Exec({"INSERT INTO flag (data, cflag, time) VALUES('PARAM01','PARAM02','PARAM03')"},;
{{Trans(Dtos(Date()),"@R 9999-99-99"),caliasflag,Time()}})) < 0
lOpen:=.T.
ELSE
WaitPeriod(100)
DO WHILE WaitPeriod()
ENDDO
oQryV:=NIL
oQryV:=oBDFlag:Query("SELECT cflag FROM flag WHERE data='PARAM01'",{Trans(Dtos(Date()),"@R 9999-99-99")})
oQryV:First()
IF oQryV:FieldGet("cflag")=caliasflag
lOpen:=.F.
ELSE
lOpen:=.T.
ENDIF
ENDIF
ELSE
oQry:First()
IF (Seconds()-Secs(oQry:FieldGet("time")))>=20
oBDFlag:Exec({"DELETE FROM flag WHERE data='PARAM01'"},{{Trans(Dtos(Date()),"@R 9999-99-99")}})
IF (oBDFlag:Exec({"INSERT INTO flag (data, cflag, time) VALUES('PARAM01','PARAM02','PARAM03')"},;
{{Trans(Dtos(Date()),"@R 9999-99-99"),caliasflag,Time()}})) < 0
lOpen:=.T.
ELSE
WaitPeriod(100)
DO WHILE WaitPeriod()
ENDDO
oQryV:=NIL
oQryV:=oBDFlag:Query("SELECT cflag FROM flag WHERE data='PARAM01'",{Trans(Dtos(Date()),"@R 9999-99-99")})
oQryV:First()
IF oQryV:FieldGet("cflag")=caliasflag
lOpen:=.F.
ELSE
lOpen:=.T.
ENDIF
ENDIF
ELSE
lOpen:=.T.
ENDIF
ENDIF
WaitPeriod(200)
DO WHILE WaitPeriod()
ENDDO
ENDDO
IF lOpen
hResponse[ 'success' ] := .T.
hResponse['cod'] := "TIMEOUT"
oController:oResponse:SendJson( hResponse )
RETURN NIL
ENDIF
Well, not a fancy solution, but it worked... now I'm not getting apache crashes with ADS Local Server but I'm getting some "errors" that I will discuss in another topic so we can separate the situations!
I haven't tested with the ADS Remote Server, I believe that there won't be any problem because ADS Remote Server has a better management than ADS Local Server, but I will test it soon.
Hope it helps you guys!