02-04-2023 9:28 AM
Hi,
Is it possible in ABAP - without work process parallelization - to parallelize multiple external HTTP requests?
Example (what I would expect to work):
Implementing this code naivly with cl_http_client is not working. The second, third, fourth (...) receive call is taking the same time like the first call.
Example Code how sth. like that would look like in JS / TS:
const prom1 = axios.get("....");
const prom2 = axios.get("....");
const [answer1, answer2] = Promise.all([prom1, prom2]);<br>
I can not really believe nth. for this is existing in ABAP, as this seems to be a very simple requirement.. Instantiating workers (i.E. using function modules) is a massive overhead for such a simple task. I want to avoid that, as it causes a drain of worker-processes, which i need for other activities (i.E. users).
Thanks,
Timo
02-04-2023 10:42 AM
It has always been more complex in ABAP (because ABAP is verbose). You can create your own generic parallelization framework and share with the community. That would be helpful.
02-04-2023 3:35 PM
sandra.rossi Thanks for your response. Maybe I wasn't clear enough or I misunderstand your answer.
I know that I can easily parallelize via ABAP work processes. The point is: I want to parallelize in the HTTP clients - not the full blown ABAP work processes (which would be a big overhead).
I would like to achieve multiple active HTTP requests for the same ABAP work process.
Background: I have a scalable REST service (not under my control) which provides me one information for one plant. I need to call it for 10 different plants.
Possibility 1: make 10 sequential calls (bah...)
Possibility 2: use abap parallelization (not good, as it blocks work processes.. It is highly possile that 20 users are executing the same code at the same time)
Possibility 3: use http (icm) paralleization - normal approach for any other runtime stack (browser / nodejs / java / ... ) I am aware of.
02-04-2023 4:10 PM
I always saw CL_HTTP_CLIENT as being a synchronous call, and never saw the possibility of asynchronous call. I wonder if the ABAP Channels would be the answer you are looking for. I never used them. I'm curious to see what other people can propose. Let's see.
02-04-2023 5:18 PM
You could either use ZTHREAD or have a look how it is implemented:
data(myThread) = new zcl_thread(aRunnable).
new zcl_thread(anotherRunnable)->start( ).
new zcl_thread(yetAnotherRunnable)->start( ).
myThread->start( ).
myThread->join( ). "waits for this specific thread"
zcl_thread=>join_all( ). "waits for all threads to finish"
02-04-2023 8:52 PM
Hi Marian,
Thanks for your response (and also the very nice thread impl.). After a quick check in github it is though still using starting new task (and therefore using a worker process).
I do not want work processes as these are a very limited resource..
Basically I would expect that the *send* command is sending (but not waiting) and the receive is waiting (compare it to await) - so the parallization is actually happening on the http receiver side.. On abap side there is just another open http request..
This way with an Extremely scalable micro service I could call the rest endpoint I.e. 1000 times at the same time.. Without wasting actual processes on sap side.
When you are fit with Javascript : nobody would do two service workers (=threads) to implement two parallel http requests. Or in Java Nobody would make two http requests.
Instead the http request itself is async..
02-07-2023 4:28 PM
Hi,
for asynchronous programming, you should check this resource:
https://codezentrale.de/tag/wait-for-asynchronous-tasks-until/
02-17-2023 1:54 PM
Answered myself here https://blogs.sap.com/2023/02/17/parallelize-cl_http_client/
02-17-2023 2:05 PM
8ae6723ab3fa43a8980099fe48f90b04 you can accept your own answer