If you would like to improve performance when calling the Marketo API, you can make concurrent requests. This approach will allow you to get more data in a shorter period of time.
When making an API request, part of the round-trip time between the client and server is the transfer time on the wire. So if we can reduce the transfer time on the wire for the requests in aggregate, we will improve performance.
The sample code below shows you how to do this in Ruby. It uses EventMachine, which is an event-processing library used for making multithreaded requests.
The example below calls the Lead Activities API, and makes two concurrent requests. This approaches eliminates the transfer time from the client to server for the second request. It does this by including the second request at the same time as the first request. The API responses are written to a text file.
#Build request URL
#Replace AAA-BBB-CCC with your Marketo instance
marketo_instance = "https://AAA-BBB-CCC.mktorest.com"
endpoint = "/rest/v1/activities.json"
#Replace with your access token
auth_token = "?access_token=" + "ac756f7a-d54d-41ac-8c3c-f2d2a39ee325:ab"
#Specify datetime needed as nextPageToken
since_date_time = ["&nextPageToken=A5YMOYZQBOGD2OSYYBYDAQGEMGLBDGDANAABQGRAQWAAKKID", "&nextPageToken=GIYDAOBNGEYS2MBWKQYDAORQGA5DAMBOGAYDAKZQGAYDALBQ"]
#Specify activities needed
activity_type_ids = "&activityTypeIds=1&activityTypeIds=12"
requesturl_a = marketo_instance + endpoint + auth_token + since_date_time.at(0) + activity_type_ids
requesturl_b = marketo_instance + endpoint + auth_token + since_date_time.at(1) + activity_type_ids
http1 = EventMachine::HttpRequest.new(requesturl_a).get
http2 = EventMachine::HttpRequest.new(requesturl_b).get
#When API response is received, write response to a text file
File.open('response1.txt', 'w') do |t|
File.open('response2.txt', 'w') do |t|