Optimize your ORDA code with requests logging

Ever need to analyze the traffic of your ORDA requests between a client and the 4D server? Sometimes it may take a while to receive a response from the server, which can make you wonder if it’s due to network traffic or to an unoptimized request you’ve written! Thankfully, 4D v17 R6 makes it possible to determine the likely reason(s) for this latency with the new ORDA methods available on the ds object. They’re not only debugging functions, they also allow you to optimize your ORDA code with a better understanding of the sent requests.

Enable ORDA requests logging

The startRequestLog() member method is very flexible since it can log ORDA requests to either a file or memory.

log to a file

To log to a file, simply call startRequestLog() with a File object indicating where your ORDA requests will be logged. In the example below, we run a query on a non-indexed field which may take some time. Thanks to this new functionality, we can check the duration of our requests:

C_OBJECT($employees;$file)
$file:=File("/PACKAGE/Logs/ORDARequests.txt")
$file.delete()
ds.startRequestLog($file)
$employees:=ds.Employee.query("firstname = :1";"abcd") //firstname is not indexed
ds.stopRequestLog()

Each request is logged as a JSON representation of an object.

Here is the content of the ORDARequests.txt file:

[
{
...
"startTime":"2019-07-02T12:33:25.922Z",
"endTime":"2019-07-02T12:33:27.681Z",
"duration":4200,
"response":{ ...}
...
}
]

log to memory

Each request can be logged as an object in a collection which can be retrieved using the getRequestLog() member method. 

Since it returns a collection, you can use all of the available collection methods.

C_OBJECT($first;$e)
C_COLLECTION($log)

ds.startRequestLog(10) // Only the last 10 requests will be kept in memory
$first:=ds.Persons.all().first()
$e:=ds.Persons.query("name=:1";"Brown")
$log:=ds.getRequestLog()
ALERT("The longest request lasted: "+String($log.max("duration"))+" ms")
ds.stopRequestLog()

disable ORDA requests logging

To stop logging ORDA requests, just call the stopRequestLog() member method as shown in the examples above.

 

Avatar
• Product Owner • Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.