Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP: Parallelize cl_http_client

TimoStark
Participant
0 Kudos

Hi,

Is it possible in ABAP - without work process parallelization - to parallelize multiple external HTTP requests?

Example (what I would expect to work):

  • Instantiate 10 HTTP Requests (cl_http_request)
  • Call "send" 10 times --> All 10 requests are processed by the external system
  • Call Receive on the first Request --> Synchronously blocks the processing until first request is done
  • Call Receive on the second Request --> Assumption, all requests are procesed identically fast, the second/third (etc..) Request should have already received the data --> no waiting

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

8 REPLIES 8

Sandra_Rossi
Active Contributor
0 Kudos

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.

TimoStark
Participant

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.

Sandra_Rossi
Active Contributor
0 Kudos

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.

Marian_Zeis
Active Contributor

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" 

0 Kudos

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..

ThorstenHoefer
Active Contributor
0 Kudos

Hi,

for asynchronous programming, you should check this resource:

https://codezentrale.de/tag/wait-for-asynchronous-tasks-until/

8ae6723ab3fa43a8980099fe48f90b04 you can accept your own answer