Hi Dan,
Thanks for that. Is there an easy way to setup separate connections within a proc?
I might be answering my own question here but on a whim I thought I would try BCP in. Now, I fully expected BCP IN to be slower than BULK INSERT but so far it has matched BULK INSERT on 60 seconds for a single large file or absolutely blitzed in in under 15 seconds. That latter was achieved by creating a batch file and then triggering that with xp_cmdshell. Unfortunately there's a load of stuff going on on the server so it is hard to isolate exactly what might be affecting my longer run times.
RESULTS OF TESTING.
ID Description RUNS--> r1 r2 r3 r4 r5
1 2 BULK INSERT statements as 1 exec 60 60 60 60 60
2 2 BULK INSERT statements separate 120 60 60 60 60
3 BULK INSERT of 1 big file 60 60 120 60 60
4 BCP 1 big file 0 60 0 0 0
5 BCP 2 files simultaneously(?!) 0 0 0 0 60
Total elapsed time
r1?!
r2?!
r3 3m 49s
r4 3m 50s
r5 3m 38s
SCRIPT FOR BCP PARTS.
DECLARE @results TABLE(id tinyint IDENTITY(1,1),d varchar(255),Duration int)
PRINT '1) 2 statements as 1 exec'
BEGIN
SET @wert = getdate()
SET @bcpquery = '
bulk insert tempdb.dbo.ParallelBulkTest from ''D:\Data\Temp\BulkLoad\DataIn1.txt'' with (fieldterminator = ''|'', rowterminator = ''\n'',FIRSTROW=1);
bulk insert tempdb.dbo.ParallelBulkTest from ''D:\Data\Temp\BulkLoad\DataIn2.txt'' with (fieldterminator = ''|'', rowterminator = ''\n'',FIRSTROW=1);
'
execute sp_executesql @bcpquery;
SET @edt = getdate()
INSERT INTO @results(d,Duration)
SELECT '2 BULK INSERT statements as 1 exec',DATEDIFF(SECOND,@wert ,@edt)
END
SELECT COUNT(*) as Records FROM ParallelBulkTest
------------------------------------------------------------------
TRUNCATE TABLE ParallelBulkTest
PRINT '2) 2 statements separate'
BEGIN
SET @wert = getdate()
bulk insert tempdb.dbo.ParallelBulkTest from 'D:\Data\Temp\BulkLoad\DataIn1.txt' with (fieldterminator = '|', rowterminator = '\n',FIRSTROW=1);
bulk insert tempdb.dbo.ParallelBulkTest from 'D:\Data\Temp\BulkLoad\DataIn2.txt' with (fieldterminator = '|', rowterminator = '\n',FIRSTROW=1);
SET @edt = getdate()
INSERT INTO @results(d,Duration)
SELECT '2 BULK INSERT statements separate',DATEDIFF(SECOND,@wert ,@edt)
END
SELECT COUNT(*) as Records FROM ParallelBulkTest
------------------------------------------------------------------
TRUNCATE TABLE ParallelBulkTest
PRINT '3) 1 big file'
BEGIN
SET @wert = getdate()
bulk insert tempdb.dbo.ParallelBulkTest from 'D:\Data\Temp\BulkLoad\DataIn0.txt' with (fieldterminator = '|', rowterminator = '\n',FIRSTROW=1);
SET @edt = getdate()
INSERT INTO @results(d,Duration)
SELECT 'BULK INSERT of 1 big file',DATEDIFF(SECOND,@wert ,@edt)
END
SELECT COUNT(*) as Records FROM ParallelBulkTest
------------------------------------------------------------------
TRUNCATE TABLE ParallelBulkTest
PRINT '4) BCP 1 big file'
BEGIN
SET @wert = getdate()
SET @CMD = 'bcp "tempdb.dbo.ParallelBulkTest" IN "D:\Data\Temp\BulkLoad\DataIn0.txt" -c -t "|" -F 1 -h "TABLOCK" /S "' + @Testta + '" -T'
exec xp_cmdshell @CMD , no_output
SET @edt = getdate()
INSERT INTO @results(d,Duration)
SELECT 'BCP 1 big file',DATEDIFF(SECOND,@wert ,@edt)
END
SELECT COUNT(*) as Records FROM ParallelBulkTest
------------------------------------------------------------------
TRUNCATE TABLE ParallelBulkTest
PRINT '5) BCP 2 files simulataneously'
BEGIN
SET @wert = getdate()
SET @CMD = 'START /b bcp.exe "tempdb.dbo.ParallelBulkTest" IN "D:\Data\Temp\BulkLoad\DataIn1.txt" -c -t "|" -F 1 -h "TABLOCK" /S "' + @Testta + '" -T
START /b bcp.exe "tempdb.dbo.ParallelBulkTest" IN "D:\Data\Temp\BulkLoad\DataIn2.txt" -c -t "|" -F 1 -h "TABLOCK" /S "' + @Testta + '" -T' ---b 10000
--PRINT @CMD
SELECT @CMD as c INTO ##A
SET @CMD = 'bcp "##A" out "' + @filepath + 'Runbat.bat" /c /t "|" /S "' + @Testta + '" -T'
exec xp_cmdshell @CMD , no_output
DROP TABLE ##A
SET @CMD = 'CALL "D:\Data\Temp\BulkLoad\Runbat.bat"'
exec xp_cmdshell @CMD , no_output
SET @edt = getdate()
INSERT INTO @results(d,Duration)
SELECT 'BCP 2 files simulataneously',DATEDIFF(SECOND,@wert ,@edt)
END
SELECT COUNT(*) as Records FROM ParallelBulkTest
SELECT * FROM @results
------------------------------------------------------------------