Some performance improvements.

This commit is contained in:
Martin Edenhofer 2015-05-01 09:44:31 +02:00
parent 8c2ea52b3c
commit 1a72bfd98a

View file

@ -89,12 +89,18 @@ module Import::OTRS2
data['Key'] = Setting.get('import_otrs_endpoint_key') data['Key'] = Setting.get('import_otrs_endpoint_key')
log 'POST: ' + url log 'POST: ' + url
log 'PARAMS: ' + data.inspect log 'PARAMS: ' + data.inspect
open_timeout = 10
read_timeout = 120
if data.empty?
open_timeout = 6
read_timeout = 20
end
response = UserAgent.post( response = UserAgent.post(
url, url,
data, data,
{ {
open_timeout: 6, open_timeout: open_timeout,
read_timeout: 60, read_timeout: read_timeout,
user: Setting.get('import_otrs_user'), user: Setting.get('import_otrs_user'),
password: Setting.get('import_otrs_password'), password: Setting.get('import_otrs_password'),
}, },
@ -343,7 +349,7 @@ module Import::OTRS2
# create customers # create customers
count = 0 count = 0
steps = 30 steps = 50
run = true run = true
while run while run
count += steps count += steps
@ -360,6 +366,8 @@ module Import::OTRS2
thread_count = 8 thread_count = 8
threads = {} threads = {}
count = 0 count = 0
memory_clear_after_loops = 10
memory_clear_loop_counter = 0
locks = { User: {} } locks = { User: {} }
(1..thread_count).each {|thread| (1..thread_count).each {|thread|
threads[thread] = Thread.new { threads[thread] = Thread.new {
@ -369,6 +377,11 @@ module Import::OTRS2
run = true run = true
steps = 20 steps = 20
while run while run
memory_clear_loop_counter++
if memory_clear_loop_counter == memory_clear_after_loops
GC.start
memory_clear_loop_counter = 0
end
count += steps count += steps
log "loading... thread# #{thread} ..." log "loading... thread# #{thread} ..."
offset = count - steps offset = count - steps
@ -512,6 +525,8 @@ module Import::OTRS2
result.each {|record| result.each {|record|
ActiveRecord::Base.transaction do
# cleanup values # cleanup values
_cleanup(record) _cleanup(record)
@ -682,7 +697,7 @@ module Import::OTRS2
end end
} }
#puts "HS: #{record['History'].inspect}" #puts "HS: #{record['History'].inspect}"
record['History'].each { |history| record['History'].each { |history|
if history['HistoryType'] == 'NewTicket' if history['HistoryType'] == 'NewTicket'
#puts "HS.add( #{history.inspect} )" #puts "HS.add( #{history.inspect} )"
@ -790,6 +805,7 @@ module Import::OTRS2
) )
end end
} }
end
} }
end end