This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Scala on the Google App Engine

7 replies
spoon
Joined: 2008-07-01,
User offline. Last seen 1 year 21 weeks ago.

Google announced last night that it is now supporting Java code on its
App Engine. It takes class files as input, so in many cases you can
take anything that will run on Tomcat or Jetty and run it on GAE
instead.

http://googleappengine.blogspot.com/

If you haven't tried it, you might want to. It's kind of fun!
Someone asked on scala-devel, many months back, how you could ever set
up a web site that hosts Scala interpreters for people. The argument
went that interpreter instances are too heavy, and so once you got
past 10 or so you'd overload the server. GAE is one answer to that
question. You could now post a Scala interpreter inside a web app on
the GAE, and then Google will start up new servers for you whenever
your load gets high. Whenever your load goes back down, it will shut
down the now-idle servers.

This is a general and really convenient ability. The same way that
geocities meant any random person can post an HTML-based web page, any
random person can now post a servlet.

The reason I'm writing this list is to talk about how well Scala
support works on GAE. Broadly, there are a good many Scala fans
floating around Google, and the general feeling from them is that
Scala apps work just fine. It seems that compiled Scala is doing a
really good imitation of well behaved Java.

One stress test, though, is causing trouble: the Scala interpreter.
Back in December, some of us verified that the Scala interpreter does
work fine on GAE. We left it alone since then. A few days ago, we
tested against a current build, and ran into a couple of problems.

1. The Java generics attribute is occasionally invalid. GAE currently
rejects class files with bad generics attributes, so if your Scala app
has one of these it will be stopped before it starts running.

http://lampsvn.epfl.ch/trac/scala/ticket/1859

A workaround should be to use -target:jvm-1.5 or, if it's still
available, -Yno-generic-signatures. Arguably GAE shouldn't even read
these attributes. However, it's certainly unintended behavior that
scalac is generating invalid ones in some cases.

2. When doing a call through a structural type, something goes wrong
with the caching. Nobody here managed to isolate the problem at this
point. We know that it shows up when Interpreter.reset() itself calls
reset() for the first time. Also, compiling with -Ystruct-dispatch:no-
cache prevents the problem. At a wild guess, maybe there is some
issue with the way the class loaders are arranged on GAE?

Getting the interpreter to work is really overkill. Typical Scala
apps seem to work fine. However, it would be great to clean up some
of these remaining corner cases. Is anyone interested?!

Regards,

Lex Spoon

dubochet
Joined: 2008-06-30,
User offline. Last seen 1 year 36 weeks ago.
Re: Scala on the Google App Engine

Hello Lex.

> The reason I'm writing this list is to talk about how well Scala
> support works on GAE. Broadly, there are a good many Scala fans
> floating around Google, and the general feeling from them is that
> Scala apps work just fine. It seems that compiled Scala is doing a
> really good imitation of well behaved Java.
>
> [...]
>
> 2. When doing a call through a structural type, something goes wrong
> with the caching. Nobody here managed to isolate the problem at
> this point. We know that it shows up when Interpreter.reset()
> itself calls reset() for the first time. Also, compiling with -
> Ystruct-dispatch:no-cache prevents the problem. At a wild guess,
> maybe there is some issue with the way the class loaders are
> arranged on GAE?

That would be strange as the compilation technique of structural
method calls doesn't do anything with class loaders.

I'll have a look at the problem. Can you send me the code that causes
it?

I applied for the Java Google early app look engine program, or
whatever it's called. Do you know how long it takes for an application
to be processed?

Cheers,
Gilles.

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Scala on the Google App Engine

On Wed, Apr 08, 2009 at 08:17:16PM -0400, Lex Spoon wrote:
> One stress test, though, is causing trouble: the Scala interpreter.

I will take general responsibility for getting this working (although I
can't guarantee how fast that will be, as I'm not yet sure how sticky
the issues are.)

> A workaround should be to use -target:jvm-1.5 or, if it's still
> available, -Yno-generic-signatures.

It's still available.

> 2. When doing a call through a structural type, something goes wrong
> with the caching. Nobody here managed to isolate the problem at this
> point.

Some tickets which may be related:

https://lampsvn.epfl.ch/trac/scala/ticket/1110
https://lampsvn.epfl.ch/trac/scala/ticket/1766

The latter also vanishes when compiling with -Ystruct-dispatch:no-cache.

On Thu, Apr 09, 2009 at 02:34:57PM +0200, Gilles Dubochet wrote:
> I'll have a look at the problem. Can you send me the code that causes it?

I also would like to see any problem code you have.

> I applied for the Java Google early app look engine program, or
> whatever it's called. Do you know how long it takes for an application
> to be processed?

I applied yesterday and they had approved me within a few hours.

spoon
Joined: 2008-07-01,
User offline. Last seen 1 year 21 weeks ago.
Re: Scala on the Google App Engine

Wow, thanks guys!

The generics problem can be observed by the code in the bug report.
The problem that Eclipse and ASM complain about is the same one that
bothers GAE. It's currently not allowed to upload .class files that
have invalid generics attributes.

For the structural types, I'm sorry that I don't have a smaller test
case right now. We tried running the interpreter inside an app engine
app and calling interpreter.reset(). This ends up calling reset() on
the structural type returned by mkNameCreator(), which causes an NPE.
Thus, an immediate workaround would be to have mkNameCreator() return
a named type instead of a structural type. However, the structural
type should also work.

On Apr 9, 2009, at 8:34 AM, Gilles Dubochet wrote:
> That would be strange as the compilation technique of structural
> method calls doesn't do anything with class loaders.

Wow, that theory didn't even last a day. It must be something else
that is different about the GAE environment from the Scala test suite.

Lex

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: Scala on the Google App Engine

On Thu, 2009-04-09 at 12:02 -0400, Lex Spoon wrote:
> Wow, thanks guys!
>
> The generics problem can be observed by the code in the bug report.
> The problem that Eclipse and ASM complain about is the same one that
> bothers GAE. It's currently not allowed to upload .class files that
> have invalid generics attributes.

This interesting. How does GAE verify this? As Paul said in another
message in the thread, it would be very useful to do something similar
during the scalac test suite. In fact, I think you suggested the same in
the mentioned bug report.

Best,
Ismael

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Scala on the Google App Engine

I already replied to the generics ticket. It seems to be fixed in
trunk. Did you try with 2.7.3, Lex? If yes, we'll just need to
backport the fix to trunk. It's in Erasure.scala -- there's can't have
been too many changes in it since 2.7.3.

Cheers

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: Scala on the Google App Engine

Hi Martin,

On Thu, 2009-04-09 at 18:17 +0200, martin odersky wrote:
> I already replied to the generics ticket. It seems to be fixed in
> trunk. Did you try with 2.7.3, Lex? If yes, we'll just need to
> backport the fix to trunk. It's in Erasure.scala -- there's can't have
> been too many changes in it since 2.7.3.

I think there's a misunderstanding here. The bug did not exist in 2.7.3,
but exists in trunk. See the responses to your comment (maybe you didn't
get notified since you're not CC'd and the bug is not assigned to you):

https://lampsvn.epfl.ch/trac/scala/ticket/1859#comment:5

Best,
Ismael

spoon
Joined: 2008-07-01,
User offline. Last seen 1 year 21 weeks ago.
Re: Scala on the Google App Engine

On Apr 9, 2009, at 9:36 AM, Ismael Juma wrote:
> On Thu, 2009-04-09 at 18:17 +0200, martin odersky wrote:
>> I already replied to the generics ticket. It seems to be fixed in
>> trunk. Did you try with 2.7.3, Lex? If yes, we'll just need to
>> backport the fix to trunk. It's in Erasure.scala -- there's can't
>> have
>> been too many changes in it since 2.7.3.
>
> I think there's a misunderstanding here. The bug did not exist in
> 2.7.3,
> but exists in trunk. See the responses to your comment (maybe you
> didn't
> get notified since you're not CC'd and the bug is not assigned to
> you):
>
> https://lampsvn.epfl.ch/trac/scala/ticket/1859#comment:5

Yes, that's my understanding as well. The generics stuff was fine in
2.7.3, so people can use that version to write GAE Scala apps.

Lex

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland