dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.56k stars 119 forks source link

ask for set up workaround to make AOT works #226

Closed guillaume-chervet closed 3 months ago

guillaume-chervet commented 4 months ago

Hi @sakno,

Thank you again for your awesome work !

SlimFaas now work in full Trim mode. But, now when I try to switch to AOT compilation I have an error at runtime (during startup). I would like to compare TRIM mode and AOT, because the lowest RAM usage is my priority.

I have the error bellow at runtime that you say it is linked to deletage constructor in discussion : https://github.com/dotnet/dotNext/discussions/200

My AOT SlimFaas PullRequest : https://github.com/AxaFrance/SlimFaas/pull/37/files

2024-03-04 13:50:19 Starting in namespace slimfaas-demo
2024-03-04 13:50:20 Starting node slimfaas-0
2024-03-04 13:50:20 Node started slimfaas-0 http://10.1.2.44:3262/
2024-03-04 13:50:20 >> Configuration: 
2024-03-04 13:50:20 - partitioning:false
2024-03-04 13:50:20 - lowerElectionTimeout:400
2024-03-04 13:50:20 - upperElectionTimeout:800
2024-03-04 13:50:20 - requestTimeout:00:01:20.0000000
2024-03-04 13:50:20 - rpcTimeout:00:00:40.0000000
2024-03-04 13:50:20 - publicEndPoint:http://10.1.2.44:3262/
2024-03-04 13:50:20 - coldStart:false
2024-03-04 13:50:20 - requestJournal:memoryLimit:5
2024-03-04 13:50:20 - requestJournal:expiration:00:01:00
2024-03-04 13:50:20 - heartbeatThreshold:0.2
2024-03-04 13:50:20 CORS Allowing origins: *
2024-03-04 13:50:20 CORS Allowing all origins
2024-03-04 13:50:20 Raft cluster has no leader
2024-03-04 13:50:20 Raft cluster has no leader
2024-03-04 13:50:20 SlimDataSynchronizationWorker: Start
2024-03-04 13:50:20 Raft cluster has no leader
2024-03-04 13:50:20 fail: Microsoft.Extensions.Hosting.Internal.Host[11]
2024-03-04 13:50:20       Hosting failed to start
2024-03-04 13:50:20       System.PlatformNotSupportedException: Operation is not supported on this platform.
2024-03-04 13:50:20          at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowPlatformNotSupportedException() + 0x20
2024-03-04 13:50:20          at System.Func`4..ctor(Object, IntPtr) + 0x6
2024-03-04 13:50:20          at DotNext.Net.Cluster.Consensus.Raft.Http.RaftHttpCluster.<StartAsync>d__45.MoveNext() + 0xa7
2024-03-04 13:50:20       --- End of stack trace from previous location ---
2024-03-04 13:50:20          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20          at Microsoft.Extensions.Hosting.Internal.Host.<<StartAsync>b__15_1>d.MoveNext() + 0xc9
2024-03-04 13:50:20       --- End of stack trace from previous location ---
2024-03-04 13:50:20          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20          at Microsoft.Extensions.Hosting.Internal.Host.<ForeachService>d__18`1.MoveNext() + 0x3d6
2024-03-04 13:50:20 Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
2024-03-04 13:50:20    at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowPlatformNotSupportedException() + 0x20
2024-03-04 13:50:20    at System.Func`4..ctor(Object, IntPtr) + 0x6
2024-03-04 13:50:20    at DotNext.Net.Cluster.Consensus.Raft.Http.RaftHttpCluster.<>c__DisplayClass47_0.<<StopAsync>g__StopAsync|0>d.MoveNext() + 0xf4
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at DotNext.Net.Cluster.Consensus.Raft.Http.RaftHttpCluster.<>c__DisplayClass47_0.<<StopAsync>g__StopAsync|0>d.MoveNext() + 0x1d2
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at DotNext.Net.Cluster.Consensus.Raft.RaftCluster`1.<DisposeAsyncCore>d__120.MoveNext() + 0xd0
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at DotNext.Disposable.<DisposeAsyncImpl>d__19.MoveNext() + 0x122
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.<<DisposeAsync>g__Await|26_0>d.MoveNext() + 0x11b
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at Microsoft.Extensions.Hosting.Internal.Host.<<DisposeAsync>g__DisposeAsync|21_0>d.MoveNext() + 0x163
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at Microsoft.Extensions.Hosting.Internal.Host.<DisposeAsync>d__21.MoveNext() + 0x4d4
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext() + 0x2dd
2024-03-04 13:50:20 --- End of stack trace from previous location ---
2024-03-04 13:50:20    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
2024-03-04 13:50:20    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
2024-03-04 13:50:20    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost) + 0x26
2024-03-04 13:50:20    at Program.<Main>$(String[] args) + 0x11bf
2024-03-04 13:50:20    at SlimFaas!<BaseAddress>+0xd30b3c

Thank you a lot for your help !

sakno commented 4 months ago

There is explanation of why it doesn't work: https://github.com/dotnet/runtime/issues/94977#issuecomment-1818184343. Therefore, it's actually an issue with AOT infrastructure. However, in this case there is a cheap workaround.

sakno commented 4 months ago

This is why this issue considered as enhancement rather than bug.

guillaume-chervet commented 3 months ago

Thank you so much @sakno for your commit !

I can't wait for the next release :)

guillaume-chervet commented 3 months ago

It works very well, thank you so much @sakno

There is a big difference in used RAM once AOT is activated.

https://github.com/AxaFrance/SlimFaas/commit/9ce057377558af0a1b60e358459e0042d8ad2f73