Code Monkey home page Code Monkey logo

Comments (7)

k1LoW avatar k1LoW commented on June 4, 2024

Hi @NBJS . Thank you for your report.

If you set subnet_id (not Name tag) as expected_subnet, you can test faster.
( Because no loop )

( In order to avoid tag duplication, ) If you set Name tag as expected_subnet, awspec has to check all subnets by using describe_subnets

Regards.

from awspec.

NBJS avatar NBJS commented on June 4, 2024

Hi @k1LoW , thanks for your response.

I have tested with subnet_ids and although it is quicker than using the name tag, it still takes a long time. This time instead of 8 minutes it took 3 minutes.

from awspec.

glasswalk3r avatar glasswalk3r commented on June 4, 2024

Are we still looking for to improve this?

I did some bench marking using a local cache from describe_subnets response without filters and looks promising:

$ ruby test.rb 
                    user     system      total        real
find_by_sub     0.051339   0.000343   0.051682 (  2.181745)
find2_by_sub    0.061501   0.000098   0.061599 (  1.143955)
find_by_cidr    0.057556   0.000000   0.057556 (  3.300872)
find2_by_cidr   0.053146   0.003496   0.056642 (  1.287103)
find_by_tag     0.021081   0.000089   0.021170 (  1.080978)
find2_by_tag    0.026609   0.000000   0.026609 (  0.584046)

where find_* refers to the original Finder::Subnet::find_subnet and find2_* refers to the function below:

def find_subnet2(subnet_id)
  res = $ec2_client.describe_subnets
  by_tag_name = {}
  by_cidr = {}
  subnet_ids = []

  res.subnets.each do |sub|
    by_cidr[sub.cidr_block.to_sym] = sub.subnet_id
    next if sub.tags.empty?

    sub.tags.each do |tag|
      if tag[:key].eql?('Name')
        by_tag_name[tag[:value].to_sym] = sub.subnet_id
        break
      end
    end

    subnet_ids.append(sub.subnet_id)
  end

  by_subinet_ids = Set.new(subnet_ids)

  if subnet_id.start_with?('subnet-')
    return subnet_id if by_subinet_ids.include?(subnet_id)
  end

  id_key = subnet_id.to_sym

  if $ip_matcher.match(subnet_id)
    return by_cidr[id_key] if by_cidr.key?(id_key)
  else
    return by_tag_name[id_key]
  end
end

Of course, we should keep the cache for the whole testing session, but that's another thing to try to implement.

from awspec.

glasswalk3r avatar glasswalk3r commented on June 4, 2024

@NBJS , I did a PR for that, could you please give it a try?

from awspec.

glasswalk3r avatar glasswalk3r commented on June 4, 2024

@k1LoW , I'm afraid the original requestor is out of reach... could you please take a look at PR #538 ?

from awspec.

glasswalk3r avatar glasswalk3r commented on June 4, 2024

@k1LoW , since PR was accepted, I think we can close this issue.

from awspec.

k1LoW avatar k1LoW commented on June 4, 2024

👍

from awspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.