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:
$employees:=ds.Employee.query("firstname = :1";"abcd") //firstname is not indexed
Each request is logged as a JSON representation of an object.
Here is the content of the ORDARequests.txt file:
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.
ds.startRequestLog(10) // Only the last 10 requests will be kept in memory
ALERT("The longest request lasted: "+String($log.max("duration"))+" ms")
disable ORDA requests logging
To stop logging ORDA requests, just call the stopRequestLog() member method as shown in the examples above.