Skip to content

Instantly share code, notes, and snippets.

@RyanSnodgrass
Last active August 19, 2016 20:44
Show Gist options
  • Select an option

  • Save RyanSnodgrass/0a45aaa28960095a2c334edcb306efbe to your computer and use it in GitHub Desktop.

Select an option

Save RyanSnodgrass/0a45aaa28960095a2c334edcb306efbe to your computer and use it in GitHub Desktop.
client = TinyTds::Client.new username: ENV["SQL_SERVER_USERNAME"],
password: ENV["SQL_SERVER_PASSWORD"],
port: ENV["SQL_SERVER_PORT"],
host: ENV["SQL_SERVER_HOST"],
database: ENV["SQL_SERVER_DB"]
query = "SELECT TOP(60000) [Institution of Higher Education Key]
   ,[Date Key]
     ,[Academic Term Key]
     ,[IPEDS Demographics Key]
     ,[IPEDS Fall Enrollment Attribute Key]
     ,[IPEDS Enrollment Headcount]
     ,[Calculated Full Time Equivalent Enrollment-Fall Headcount Basis]
 FROM [dw].[IPEDS Fall Enrollment Fact]
GO"
result = client.execute("EXECUTE AS USER='ADND\\rsnodgra' #{query}")
report = MemoryProfiler.report do
CSV.open('dataset_exports/tinytds_memory_test.csv', 'w') do |csv|
csv << result.fields
result.each(:as => :array, :cache_rows => false) do |row|
csv << row
end
end
end
report.pretty_print
# 74.449254 MB of memory
allocated memory by gem
-----------------------------------
41808214 ruby-2.1.8/lib
19200000 activesupport-4.1.15
13441040 other
allocated memory by file
-----------------------------------
41808214 /usr/local/rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/csv.rb
16800000 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/activesupport-4.1.15/lib/active_support/core_ext/numeric/conversions.rb
13441040 (irb)
2400000 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/activesupport-4.1.15/lib/active_support/core_ext/big_decimal/conversions.rb
#####################
#####################
#####################
#####################
@db = Sequel.tinytds user: ENV["SQL_SERVER_USERNAME"],
password: ENV["SQL_SERVER_PASSWORD"],
port: ENV["SQL_SERVER_PORT"],
host: ENV["SQL_SERVER_HOST"],
database: ENV["SQL_SERVER_DB"],
timeout: 20
query = "SELECT TOP(60000) [Institution of Higher Education Key]
   ,[Date Key]
     ,[Academic Term Key]
     ,[IPEDS Demographics Key]
     ,[IPEDS Fall Enrollment Attribute Key]
     ,[IPEDS Enrollment Headcount]
     ,[Calculated Full Time Equivalent Enrollment-Fall Headcount Basis]
 FROM [dw].[IPEDS Fall Enrollment Fact]
GO"
report = MemoryProfiler.report do
CSV.open('dataset_exports/sequel_memory_test.csv', 'w') do |csv|
csv << @db["EXECUTE AS USER='ADND\\rsnodgra'; #{query}"].first.keys
@db["EXECUTE AS USER='ADND\\rsnodgra'; #{query}"].each do |row|
csv << row.values
end
end
end
report.pretty_print
# 105.182268 MB
Total allocated: 105182268 bytes (1440296 objects)
Total retained: 1411 bytes (12 objects)
allocated memory by gem
-----------------------------------
41808494 ruby-2.1.8/lib
38411103 sequel-4.35.0
19200000 activesupport-4.1.15
5761534 other
1137 tiny_tds-1.0.4
allocated memory by file
-----------------------------------
41808494 /usr/local/rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/csv.rb
38405678 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/sequel-4.35.0/lib/sequel/adapters/tinytds.rb
16800000 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/activesupport-4.1.15/lib/active_support/core_ext/numeric/conversions.rb
5761534 (irb)
2400000 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/activesupport-4.1.15/lib/active_support/core_ext/big_decimal/conversions.rb
2441 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/sequel-4.35.0/lib/sequel/dataset/actions.rb
1352 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/sequel-4.35.0/lib/sequel/dataset/query.rb
1137 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/tiny_tds-1.0.4/lib/tiny_tds/client.rb
1008 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/sequel-4.35.0/lib/sequel/database/connecting.rb
464 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/sequel-4.35.0/lib/sequel/connection_pool/threaded.rb
160 /usr/local/rvm/gems/ruby-2.1.8@Fenrir/gems/sequel-4.35.0/lib/sequel/database/dataset.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment