Skip to content

newEnv discover adds excessive latency in latest code #1018

Open
@matteoeghirotta

Description

Hi, thanks for this great project.
Relatively new to Haskell, but with working experience with AWS SDK for js (node).
I just started exploring amazonka to develop some command-line utilities with this sdk.
All good with the latest release, but noticed it was a bit outdated, so I tried switching to the latest commit in main.
At this point I started to notice some serious slowdown, 30 secs latency just to execute this silly snip:

main = do
  env <- newEnv discover

I tracked the origin of the "problem" down to the merge of the arianvp/fix-aws-sso branch, 5461403 .
From this point on 30 secs extra latency gets added to every program trying to set the env.
Went to profiling the whole thing to understand why, with no luck, all being assigned to SYSTEM, so RTS doing its business:

   try +RTS -pa -hm -RTS

total time  =       29.77 secs   (29765 ticks @ 1000 us, 1 processor)
total alloc =  12,362,808 bytes  (excludes profiling overheads)
COST CENTRE                      MODULE                                       SRC                                                                    %time %alloc  ticks     bytes

SYSTEM                                SYSTEM                                        <built-in>                                                              99.5    0.3  29608     34760
readCertificates                    Data.X509.CertificateStore           Data/X509/CertificateStore.hs:(93,1)-(97,33)           0.2   58.2     60   7195424
GC                                         GC                                              <built-in>                                                                 0.1    0.0     39      4560

versus the release amazonka:

   try +RTS -pa -hm -RTS

total time  =        0.01 secs   (12 ticks @ 1000 us, 1 processor)
total alloc =  11,720,176 bytes  (excludes profiling overheads)
COST CENTRE              MODULE                              SRC                                                                %time %alloc  ticks     bytes

GC                                GC                                       <built-in>                                                            33.3    0.0      4      4536
readCertificates            Data.X509.CertificateStore   Data/X509/CertificateStore.hs:(93,1)-(97,33)       25.0   61.4      3   7195424
envHelper                    Network.HTTP.Proxy             Network/HTTP/Proxy.hs:(338,1)-(380,87)             16.7   16.9      2   1985096
readCertificateStore     Data.X509.CertificateStore    Data/X509/CertificateStore.hs:(75,1)-(87,50)       16.7   17.9      2   2093536

Looking at the new code it seems the origin of the extra latency is the discover function lib/amazonka/src/Amazonka/Auth.hs:117, in which a DNS lookup is always performed to check if the process is running inside an EC2.

The problem is, this adds up 30 extra secs always, which I think it's not acceptable in latency sensitive apps, like CLIs and lambda.

My question is: are we ok with that ? Maybe someone already noticed that and there is some workaround I'm not aware of?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions