Hot code loading

852 views
Skip to first unread message

Archos

unread,
Jul 6, 2010, 7:24:30 AM7/6/10
to golang-nuts
Would be possible to get hot code loading (like Erlang has) into a
compiled language like Go?

It would be very great since it lets to upgrade the server code
without shutting it down.

http://stackoverflow.com/questions/2968914/code-hot-swapping-in-erlang

bflm

unread,
Jul 6, 2010, 9:02:21 AM7/6/10
to golang-nuts
How do you expect the type system to cope with the new/modified types
in the upgraded code mixed with the old one types?

John Asmuth

unread,
Jul 6, 2010, 9:17:42 AM7/6/10
to golang-nuts
All things are possible, if the underlying semantics are clear. How he
expects the implementation to work is irrelevant. I am not a web-
oriented developer, but it seems to be that this feature would be
extremely useful for production web sites, and be a big plus in go's
basket if it existed.

Archos

unread,
Jul 6, 2010, 10:36:12 AM7/6/10
to golang-nuts
Erlang is dynamically typed, so that's no problem. It's true that into
a statically typed language that kind of thing is indeed problematic.

But the usual approach could be to build a tree of dependencies, and
then upgrade all of those atomically. Or it might just go the simple
route by not allowing any types to change between upgrades.

In Java, you have the OSGi project [1] and hotswap [2], which
facilitates upgrading and changing modules of your application without
touching other modules.


[1] http://www.osgi.org/Main/HomePage
[2] http://code.google.com/p/hotswap/

Archos

unread,
Jul 6, 2010, 11:45:17 AM7/6/10
to golang-nuts

On Jul 6, 2:36 pm, Archos <raul....@sent.com> wrote:
> But the usual approach could be to build a tree of dependencies, and
> then upgrade all of those atomically. Or it might just go the simple
> route by not allowing any types to change between upgrades.
>
> In Java, you have the OSGi project [1] and hotswap [2], which
> facilitates upgrading and changing modules of your application without
> touching other modules.
It's also interesting the technique used by the Nginx web server to
emulate it:

1. Use the spawn family of system calls (ex. spawnl spawnvp) with the
flag P_NOWAIT to execute itself. This new process has access to the
open sockets.

2. The new process should open a predetermined file containing the
file descriptors of the sockets it needs to use saved by the old
process.

3. Start calling “accept” on the same listening sockets that the old
process was accepting.

4. Signal the old process to stop accepting, and to quit when all
requests are finished.


http://www.codexon.com/posts/hot-code-swapping-for-servers-not-written-in-erlang

jart

unread,
Jul 6, 2010, 6:39:08 PM7/6/10
to golang-nuts
> It's also interesting the technique used by the Nginx web server to
> emulate it:

I fully support this approach over what Erlang does. One obstacle you
might have to overcome is clearing the O_CLOEXEC flag which is a new
Linux feature that prevents child processes from inheriting file
descriptors. I'm not entirely certain how it one would go about
clearing this flag.
Reply all
Reply to author
Forward
0 new messages