Android Question jRDC2 : Successful Operation on Server but TimeOut Error on Client

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I ran a jRDC via command prompt on Windows. The Operation on server is OK (see the attached picture)
Err.jpg


but on Android device, got TimeOut Error Connection.

These are the codes for those commands
B4X:
Sub Test
     Dim cmd As DBCommand
     cmd.Initialize
     cmd.Name = "del_bi_tbl"
    
     wait for (reqM.ExecuteCommand(cmd,"del_bi_tbl")) JobDone (job As HttpJob)

     If job.success Then
          Dim cmd As DBCommand
          cmd.Initialize
          cmd.Name = "ins_bi_tbl1"
          cmd.Parameters = Array As Object("01/01/2019","31/03/2019")
          reqM.ExecuteCommand(cmd, "ins_bi_tbl1")

          Dim cmd As DBCommand
          cmd.Initialize
          cmd.Name = "ins_bi_tbl2"
          cmd.Parameters = Array As Object("01/04/2019","30/06/2019")
          reqM.ExecuteCommand(cmd, "ins_bi_tbl2")
   End If
End Sub

Sub JobDone(Job As HttpJob)
     If Job.Success = False Then
         log(Job.ErrorMessage)
     Else
         Dim result As DBResult = reqM.HandleJob(Job)
         Log(result.Tag)
     End If
End Sub

Internet Connection is OK. I have already set j.GetRequest.Timeout = 300000
Any hints, how to handle this problem?
 

incendio

Well-Known Member
Licensed User
Longtime User
I have tried to change the codes to
B4X:
Sub Test
     Dim cmd As DBCommand
     cmd.Initialize
     cmd.Name = "del_bi_tbl"
    
     wait for (reqM.ExecuteCommand(cmd,"del_bi_tbl")) JobDone (job As HttpJob)

     If job.success Then
          job.release

          Dim cmd As DBCommand
          cmd.Initialize
          cmd.Name = "ins_bi_tbl1"
          cmd.Parameters = Array As Object("01/01/2019","30/06/2019")

          wait for (reqM.ExecuteCommand(cmd,"ins_bi_tbl1")) JobDone (job As HttpJob)

          If job.success Then
              job.release
          else
              log(Job.ErrorMessage)
              job.release
          end if
   else 
        job.release
   End If
End Sub
Although on Server the operation is OK, but on Android device, still got TimeoutError.
The operation on server took about 120 seconds to finished.
It seem that operation on server that took more than 60 seconds mostly will give TimeOutError to client.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
My code is right, basically it was the same pattern with the recommended one.

The command is to summarised data and inserted the results to the table.

I can verified that the operation indeed inserted data to the targeted table.

There is nothing wrong with the time took to do the operation cause it involves big data, total summarised records were about 550K.

Here is the command look like
B4X:
Insert into rcp_tbl select * from stored_proc("01/01/19","12/31/19")
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
My code is right, basically it was the same pattern with the recommended one.
No. Check it again. You are expected to create a new DBRequestManager for each request.

There is nothing wrong with the time took to do the operation cause it involves big data, total summarised records were about 550K.
Looks a bit slow to me. I would have tried to optimize.

You can change the client timeout by adding this line to SendJob after j.PostBytes:
B4X:
    j.GetRequest.Timeout = 600000
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have already set the Timeout on client to 300K, setting it to 600K, even if it successful, will be to long for users.

What I don't understand is, on server, the operation finished about 120 seconds, why took so long to send respond to client?

It seems that server has timeout too, when it reaches certain time, it will stop trying to send respond to clients.

Is there some parameters on server to set timeout?
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have set TimeOut to 600K and change codes into like these
B4X:
Sub Test
     THREADS = 12
     ProgressDialogShow2("Please wait ...")
     Dim req As DBRequestManager = CreateRequest
        
     Dim cmd As DBCommand = CreateCommand("del_bi_tbl", Null)
     wait for (req.ExecuteCommand(cmd,"del_bi_tbl")) JobDone (job As HttpJob)
     If job.success Then
           Private Yr,RptDt1,RptDt2 As String
           Yr = DateTime.GetYear(DateTime.Now)-2000
           
           For i = 1 To 12
               If i = 1 Then
                   RptDt1 = "01/01/" & Yr
                   RptDt2 = "31/01/" & Yr
               else if i = 2 Then
                   RptDt1 = "01/02/" & Yr
                   RptDt2 = "28/02/" & Yr
               else if i = 3 Then
                   RptDt1 = "01/03/" & Yr
                   RptDt2 = "31/03/" & Yr
               else if i = 4 Then
                   RptDt1 = "01/04/" & Yr
                   RptDt2 = "30/04/" & Yr
               else if i = 5 Then
                   RptDt1 = "01/05/" & Yr
                   RptDt2 = "31/05/" & Yr
               else if i = 6 Then
                   RptDt1 = "01/06/" & Yr
                   RptDt2 = "30/06/" & Yr
               else if i = 7 Then
                   RptDt1 = "01/07/" & Yr
                   RptDt2 = "31/07/" & Yr
               else if i = 8 Then
                   RptDt1 = "01/08/" & Yr
                   RptDt2 = "31/08/" & Yr
               else if i = 9 Then
                   RptDt1 = "01/09/" & Yr
                   RptDt2 = "30/09/" & Yr
               else if i = 10 Then
                   RptDt1 = "01/10/" & Yr
                   RptDt2 = "31/10/" & Yr
               else if i = 11 Then
                   RptDt1 = "01/11/" & Yr
                   RptDt2 = "30/11/" & Yr
               else if i = 12 Then
                   RptDt1 = "01/12/" & Yr
                   RptDt2 = Utility.Str2Dt("31/12/" & Yr)
               End If
               
               Dim req As DBRequestManager = CreateRequest
               Dim cmd As DBCommand = CreateCommand("ins_bi_tbl", Array (RptDt1,RptDt2))
               req.ExecuteCommand(cmd, "ins_bi_tbl" & i)
           Next
     End If
     job.Release
End Sub

Sub JobDone(Job As HttpJob)
   If Job.Success = False Then
       ProgressDialogHide
       Log(Job.ErrorMessage)
   Else
       Dim result As DBResult = reqM.HandleJob(Job)
       Log(result.Tag)

       Log("Threads : " & THREADS)
       THREADS = THREADS - 1
           
       If THREADS = 0 Then
           Log("Ins finished")
           ProgressDialogHide
           Log(DateTime.Time(DateTime.Now))
       End If
   End If
End Sub

Still Error. Seem that server will stop to give response to client for every operation that takes more than 90 secs
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Could it be related to idle timeout on server?
Back in old RDC there is a c3p proprerties file to set this parameter, how to set parameter in jrRDC2?

Anyway, you were right, 90 sec or more is to long for client. I have to find another way that speed up the process.

Btw, why use DBRequestManager for each request? Usually I only use 1 DBRequestManager for every request and never had any problems.

Thanks anyway for your help.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Could it be related to idle timeout on server?
I don't think so as there would have been an error message in the server logs.

Back in old RDC there is a c3p proprerties file to set this parameter, how to set parameter in jrRDC2?
Please start a new thread for this in B4J forum.

Btw, why use DBRequestManager for each request? Usually I only use 1 DBRequestManager for every request and never had any problems.
1. It is always a good idea to follow the recommended pattern, especially if the developer insists that is is important ;)
2. You will have problems when multiple responses arrive more or less together.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
is there any reason why you loop the process per month ? what happen if you process data for a year in one execute process ?
To force firebird server to use available cores in server. With single connection, firebird will only use 1 core & this will take longer time.
 
Upvote 0
Top