Asynchronous execution of scala program in spark-submit












0















I have noticed that my scala program doesn't work as expected.



Basically, it connects by jdbc with one database and calls to one stored procedure, which load a table with, for example, 1000 rows (one by one).



The next step in my scala program is read that table and do some calculations. Here is where the problem arises, because it reads less rows (for example, about 30) instead of the 1000.



This evidently points that the distribution of the application into the cluster by spark is not waiting properly to let the SP finish its job and it carries on with the next instruction before expected.



I have added a Thread.sleep(10000) and the situation improves, but I don't like at all use that workaround to solve this problem.



I have tried also to execute the application with just one Executor and the issue persists.



Someone of you guys have had this issue too? How did you resolve it?



Thanks in advance





Sample Code:



// sp which generates 1000 records in one table in database
mMeta.getConnection().prepareCall("{call " + mMeta.getDatabaseName + ".[dbo].SP_Create1000rows}")

// method which grabs the rows from database created in previous code
Process1000rows()


The method Process1000rows gets about 40 rows, because it's not waiting for the stored procedure to be done.



However, if I add a Thread.sleep(10000) between both instructions, the method takes the 1000 rows generated by the SP.



Hope it's clearer now...










share|improve this question




















  • 1





    Hard to say w/o a code sample. Most probably you you don't consume the result of the remote computation. Each manipulation with an RDD must finish with a terminal action (collect, count, etc). Without a terminal action in general no actions will be executed.

    – simpadjo
    Nov 23 '18 at 10:25











  • Hi @simpadjo, thanks for your anser, I am gonna add a sample, but I am afraid it won't be more usefull than the description, give me a while...

    – Jaime Drq
    Nov 23 '18 at 10:49











  • Why is it even marked with apache-spark? You don't seem to use any Spark constructs, and without these it is just a normal Scala app.

    – user10465355
    Nov 23 '18 at 11:01











  • Yes, the "spark part" comes after, because the rows contains a query that will be launched by spark to load the data into the cloudera cluster

    – Jaime Drq
    Nov 23 '18 at 11:11











  • and... @user10465355, it's a normal scala app, but executed with spark-submit, so it's related.

    – Jaime Drq
    Nov 23 '18 at 11:31
















0















I have noticed that my scala program doesn't work as expected.



Basically, it connects by jdbc with one database and calls to one stored procedure, which load a table with, for example, 1000 rows (one by one).



The next step in my scala program is read that table and do some calculations. Here is where the problem arises, because it reads less rows (for example, about 30) instead of the 1000.



This evidently points that the distribution of the application into the cluster by spark is not waiting properly to let the SP finish its job and it carries on with the next instruction before expected.



I have added a Thread.sleep(10000) and the situation improves, but I don't like at all use that workaround to solve this problem.



I have tried also to execute the application with just one Executor and the issue persists.



Someone of you guys have had this issue too? How did you resolve it?



Thanks in advance





Sample Code:



// sp which generates 1000 records in one table in database
mMeta.getConnection().prepareCall("{call " + mMeta.getDatabaseName + ".[dbo].SP_Create1000rows}")

// method which grabs the rows from database created in previous code
Process1000rows()


The method Process1000rows gets about 40 rows, because it's not waiting for the stored procedure to be done.



However, if I add a Thread.sleep(10000) between both instructions, the method takes the 1000 rows generated by the SP.



Hope it's clearer now...










share|improve this question




















  • 1





    Hard to say w/o a code sample. Most probably you you don't consume the result of the remote computation. Each manipulation with an RDD must finish with a terminal action (collect, count, etc). Without a terminal action in general no actions will be executed.

    – simpadjo
    Nov 23 '18 at 10:25











  • Hi @simpadjo, thanks for your anser, I am gonna add a sample, but I am afraid it won't be more usefull than the description, give me a while...

    – Jaime Drq
    Nov 23 '18 at 10:49











  • Why is it even marked with apache-spark? You don't seem to use any Spark constructs, and without these it is just a normal Scala app.

    – user10465355
    Nov 23 '18 at 11:01











  • Yes, the "spark part" comes after, because the rows contains a query that will be launched by spark to load the data into the cloudera cluster

    – Jaime Drq
    Nov 23 '18 at 11:11











  • and... @user10465355, it's a normal scala app, but executed with spark-submit, so it's related.

    – Jaime Drq
    Nov 23 '18 at 11:31














0












0








0








I have noticed that my scala program doesn't work as expected.



Basically, it connects by jdbc with one database and calls to one stored procedure, which load a table with, for example, 1000 rows (one by one).



The next step in my scala program is read that table and do some calculations. Here is where the problem arises, because it reads less rows (for example, about 30) instead of the 1000.



This evidently points that the distribution of the application into the cluster by spark is not waiting properly to let the SP finish its job and it carries on with the next instruction before expected.



I have added a Thread.sleep(10000) and the situation improves, but I don't like at all use that workaround to solve this problem.



I have tried also to execute the application with just one Executor and the issue persists.



Someone of you guys have had this issue too? How did you resolve it?



Thanks in advance





Sample Code:



// sp which generates 1000 records in one table in database
mMeta.getConnection().prepareCall("{call " + mMeta.getDatabaseName + ".[dbo].SP_Create1000rows}")

// method which grabs the rows from database created in previous code
Process1000rows()


The method Process1000rows gets about 40 rows, because it's not waiting for the stored procedure to be done.



However, if I add a Thread.sleep(10000) between both instructions, the method takes the 1000 rows generated by the SP.



Hope it's clearer now...










share|improve this question
















I have noticed that my scala program doesn't work as expected.



Basically, it connects by jdbc with one database and calls to one stored procedure, which load a table with, for example, 1000 rows (one by one).



The next step in my scala program is read that table and do some calculations. Here is where the problem arises, because it reads less rows (for example, about 30) instead of the 1000.



This evidently points that the distribution of the application into the cluster by spark is not waiting properly to let the SP finish its job and it carries on with the next instruction before expected.



I have added a Thread.sleep(10000) and the situation improves, but I don't like at all use that workaround to solve this problem.



I have tried also to execute the application with just one Executor and the issue persists.



Someone of you guys have had this issue too? How did you resolve it?



Thanks in advance





Sample Code:



// sp which generates 1000 records in one table in database
mMeta.getConnection().prepareCall("{call " + mMeta.getDatabaseName + ".[dbo].SP_Create1000rows}")

// method which grabs the rows from database created in previous code
Process1000rows()


The method Process1000rows gets about 40 rows, because it's not waiting for the stored procedure to be done.



However, if I add a Thread.sleep(10000) between both instructions, the method takes the 1000 rows generated by the SP.



Hope it's clearer now...







scala apache-spark






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 11:15







Jaime Drq

















asked Nov 23 '18 at 9:34









Jaime DrqJaime Drq

626312




626312








  • 1





    Hard to say w/o a code sample. Most probably you you don't consume the result of the remote computation. Each manipulation with an RDD must finish with a terminal action (collect, count, etc). Without a terminal action in general no actions will be executed.

    – simpadjo
    Nov 23 '18 at 10:25











  • Hi @simpadjo, thanks for your anser, I am gonna add a sample, but I am afraid it won't be more usefull than the description, give me a while...

    – Jaime Drq
    Nov 23 '18 at 10:49











  • Why is it even marked with apache-spark? You don't seem to use any Spark constructs, and without these it is just a normal Scala app.

    – user10465355
    Nov 23 '18 at 11:01











  • Yes, the "spark part" comes after, because the rows contains a query that will be launched by spark to load the data into the cloudera cluster

    – Jaime Drq
    Nov 23 '18 at 11:11











  • and... @user10465355, it's a normal scala app, but executed with spark-submit, so it's related.

    – Jaime Drq
    Nov 23 '18 at 11:31














  • 1





    Hard to say w/o a code sample. Most probably you you don't consume the result of the remote computation. Each manipulation with an RDD must finish with a terminal action (collect, count, etc). Without a terminal action in general no actions will be executed.

    – simpadjo
    Nov 23 '18 at 10:25











  • Hi @simpadjo, thanks for your anser, I am gonna add a sample, but I am afraid it won't be more usefull than the description, give me a while...

    – Jaime Drq
    Nov 23 '18 at 10:49











  • Why is it even marked with apache-spark? You don't seem to use any Spark constructs, and without these it is just a normal Scala app.

    – user10465355
    Nov 23 '18 at 11:01











  • Yes, the "spark part" comes after, because the rows contains a query that will be launched by spark to load the data into the cloudera cluster

    – Jaime Drq
    Nov 23 '18 at 11:11











  • and... @user10465355, it's a normal scala app, but executed with spark-submit, so it's related.

    – Jaime Drq
    Nov 23 '18 at 11:31








1




1





Hard to say w/o a code sample. Most probably you you don't consume the result of the remote computation. Each manipulation with an RDD must finish with a terminal action (collect, count, etc). Without a terminal action in general no actions will be executed.

– simpadjo
Nov 23 '18 at 10:25





Hard to say w/o a code sample. Most probably you you don't consume the result of the remote computation. Each manipulation with an RDD must finish with a terminal action (collect, count, etc). Without a terminal action in general no actions will be executed.

– simpadjo
Nov 23 '18 at 10:25













Hi @simpadjo, thanks for your anser, I am gonna add a sample, but I am afraid it won't be more usefull than the description, give me a while...

– Jaime Drq
Nov 23 '18 at 10:49





Hi @simpadjo, thanks for your anser, I am gonna add a sample, but I am afraid it won't be more usefull than the description, give me a while...

– Jaime Drq
Nov 23 '18 at 10:49













Why is it even marked with apache-spark? You don't seem to use any Spark constructs, and without these it is just a normal Scala app.

– user10465355
Nov 23 '18 at 11:01





Why is it even marked with apache-spark? You don't seem to use any Spark constructs, and without these it is just a normal Scala app.

– user10465355
Nov 23 '18 at 11:01













Yes, the "spark part" comes after, because the rows contains a query that will be launched by spark to load the data into the cloudera cluster

– Jaime Drq
Nov 23 '18 at 11:11





Yes, the "spark part" comes after, because the rows contains a query that will be launched by spark to load the data into the cloudera cluster

– Jaime Drq
Nov 23 '18 at 11:11













and... @user10465355, it's a normal scala app, but executed with spark-submit, so it's related.

– Jaime Drq
Nov 23 '18 at 11:31





and... @user10465355, it's a normal scala app, but executed with spark-submit, so it's related.

– Jaime Drq
Nov 23 '18 at 11:31












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443979%2fasynchronous-execution-of-scala-program-in-spark-submit%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443979%2fasynchronous-execution-of-scala-program-in-spark-submit%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?