Erlang and sleep mode under Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang and sleep mode under Windows

Frank Muller
Hi

I’ve a simple Erlang application under Windows. It runs under erlsrv.exe and all is good.

However, I’ve noticed that when the machine enters sleep mode, my app "must be manually restarted" to work again.

The reason is still not clear to me, but i suspect the fact that it loses internet connectivity.

Questions:
1. Can I detect the sleep mode and recover from it programmatically?
2. To avoid restarting the app, is it possible to restart only the networking part of the VM (not even sure if such a thing exits/feasible)?

Thanks in advance.

/Frank

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang and sleep mode under Windows

Sergej Jurečko
Use erlang:send_after and measure the time it actually took for the message to arrive. If it’s much longer the machine was in sleep mode. Don’t know about the networking issues. You could do init:restart() if it’s really necessary.


Regards,
Sergej

On 7 Sep 2017, at 06:49, Frank Muller <[hidden email]> wrote:

Hi

I’ve a simple Erlang application under Windows. It runs under erlsrv.exe and all is good.

However, I’ve noticed that when the machine enters sleep mode, my app "must be manually restarted" to work again.

The reason is still not clear to me, but i suspect the fact that it loses internet connectivity.

Questions:
1. Can I detect the sleep mode and recover from it programmatically?
2. To avoid restarting the app, is it possible to restart only the networking part of the VM (not even sure if such a thing exits/feasible)?

Thanks in advance.

/Frank
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang and sleep mode under Windows

zxq9-2
In reply to this post by Frank Muller
On 2017年09月07日 木曜日 04:49:07 Frank Muller wrote:
> 1. Can I detect the sleep mode and recover from it programmatically?

No idea. This is an interesting question, though. I imagine Windows provides some way of figuring this out -- perhaps through a registry query.

That said, since Linux, OSX and Windows all have power states it would certainly be useful if the EVM provided some way to subscribe to OS power state changes.

-spec os:subscribe(pid(), power_state) -> ok | {error, term()}.

(Looking at the spec of that function I am obviously envisioning more uses for that than just power states...)

> 2. To avoid restarting the app, is it possible to restart only the
> networking part of the VM (not even sure if such a thing exits/feasible)?

I don't think there is a way right now to detect sleep mode or "I've just woken back up!" without writing a native Windows service to notify you, but it IS possible to check whether your socket is still connected and programmatically recover from this. Provide a check and reconnect for when a connection goes down and it should handle your network failures for you. Incidentally, that will also make moving between networks work more smoothly.

Losing connectivity between sleep intervals or between network transitions and IP reassignments is just a reality of modern client-side coding.

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang and sleep mode under Windows

zxq9-2
On 2017年09月07日 木曜日 15:03:09 zxq9 wrote:
> -spec os:subscribe(pid(), power_state) -> ok | {error, term()}.
>
> (Looking at the spec of that function I am obviously envisioning more uses for that than just power states...)

Now that I take a second look at that, it is clear to me that an AHCI subscription and query interface would be immensely useful.

A cursory search doesn't bring anything up in this area for Erlang. IMO, this sort of thing really would belong in the runtime.

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang and sleep mode under Windows

zxq9-2
On 2017年09月07日 木曜日 15:07:23 zxq9 wrote:
> On 2017年09月07日 木曜日 15:03:09 zxq9 wrote:
> > -spec os:subscribe(pid(), power_state) -> ok | {error, term()}.
> >
> > (Looking at the spec of that function I am obviously envisioning more uses for that than just power states...)
>
> Now that I take a second look at that, it is clear to me that an AHCI subscription and query interface would be immensely useful.

And ACPI. (I was conflating these two in my mind.)

Along with that, any other similar generally uniformly available power/hardware/system status type protocols.

I believe the best we can do at the moment is figure out which environment we're in and open a port or make a query (if available) via os:command/1. It might be possible to tail a log file in some environments. Anyway, this seems a lot trickier to work out than having runtime interfaces to AHCI, ACPI, etc.

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions