Re: Fast execution of scripts

Kevin Wright <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <CABHxxC3JRqhPxFgPSfUR_7AJ9bOQN3kND788sk9qkuj3DGyvXQ@mail.gmail.com>
Old problem, already solved:

http://www.martiansoftware.com/nailgun/

On 15 February 2015 at 12:36, Oliver Ruebenacker <[email protected]> wrote:

>
>      Hello,
>
>   Clever idea. The obvious drawback is that you are now running two JVMs,
> one for the server and one for the client. JVMs can be rather big,
> depending on your setup. Also, if two clients ever want to run
> simultaneously on the same machine, they'd conflict over network ports.
>
>   It is an interesting question why your client runs so much faster. It
> still needs on every invocation to start up a new JVM and load the Java
> runtime classes. The only reason I can think of is that is does not need to
> load the Scala runtime and Scala compiler classes each time. But two
> seconds seems like a long time for this.
>
>   Probably the scala command can be made a lot faster by reading the Scala
> runtime and compiler classes from a faster disk, maybe even a RAM disk.
>
>   It would be awesome if the scala command could be made to avoid starting
> a new JVM each time.
>
>      Best, Oliver
>
> On Sun, Feb 15, 2015 at 1:39 AM, SpiderPig <[email protected]> wrote:
>
>> I often use Scala in script mode and have always been annoyed at the slow
>> compile speed. It takes about 2 - 3 seconds for a script (run with "scala
>> script.scala") to start.
>> But recently I learned there is a way to start a scala script much faster.
>>
>> Here is some example code that demonstrates this. First you start
>> ScriptServer.scala and afterwards you can run any scala script with "java
>> RunScript script.scala". The first time it still takes 2 seconds but all
>> future invocations run in less than 200 ms.
>> Now that raises the question if it is possible to add a command line
>> option to scala that lets you run scripts that fast. There probably is some
>> drawback to this approach I'm not aware of but I'm guessing it would work
>> at least for most small scripts.
>>
>> ScriptServer.scala:
>> import javax.script._
>> import java.net._
>>
>> val engine = new ScriptEngineManager().getEngineByName("scala")
>>
>> val ss = new ServerSocket(10123)
>>
>> while(true) {
>>   val so = ss.accept()
>>   val in = scala.io.Source.fromInputStream(so.getInputStream)
>>   val script = engine.asInstanceOf[Compilable].compile(in.mkString)
>>   script.eval()
>> }.
>>
>> RunScript.java:
>> import java.io.PrintWriter;
>> import java.net.Socket;
>> import java.nio.file.*;
>> import java.util.List;
>>
>> public class RunScript {
>>   public static void main(String[] args) throws Exception {
>>     String name = args[0];
>>     List<String> lines = Files.readAllLines(Paths.get(name));
>>     PrintWriter out = new PrintWriter(new Socket("localhost",
>> 10123).getOutputStream());
>>     for(String line: lines) {
>>       out.println(line);
>>     }
>>     out.flush();
>>     out.close();
>>   }
>> }
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "scala-language" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Oliver Ruebenacker
> Solutions Architect at Altisource Labs <http://www.altisourcelabs.com/>
> Be always grateful, but never satisfied.
>
> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Kevin Wright
mail: [email protected]
gtalk / msn : [email protected]
quora: http://www.quora.com/Kevin-Wright
google+: http://gplus.to/thecoda
<[email protected]>
twitter: @thecoda
vibe / skype: kev.lee.wright
steam: kev_lee_wright

"My point today is that, if we wish to count lines of code, we should not
regard them as "lines produced" but as "lines spent": the current
conventional wisdom is so foolish as to book that count on the wrong side
of the ledger" ~ Dijkstra

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.