2

私は組み込みのスクリプト言語として python2.6 を持つ ETL ツールを使用しているため、ダウンストリーム処理のために大きなファイルをチャンクに分割する必要があったとき。それは当然の選択に思えた。最初に、python 2.6 インストールを使用して、Macbook ( osx 10.8 ) でスクリプトを作成してテストしました。

これを Windows に移動したとき、実行速度が 10 倍遅くなったことに驚きました... エンタープライズ規模のサーバー (32 コア 64 GB ファイバーチャネル SAN など) でさえも。

違いがどこにあるのかを絞り込もうとすると、書き込みをコメントアウトすると、mac osx はほとんど違いを示さないのに対し、windows は > 5 倍に増加します。

osx と windows の間に基本的なファイル IO の違いはありますか?

どんな助けでもありがたく受け入れました:)

import os
import sys
import re
from time import time

t = time()


"""
# Split a pre sorted text file into multiple outputs based on the leftmost element
# delimited by spaces.
# The second element can be used for an additional sort and will stripped from the 
# output when 'isLeadingSort=1'
#
# parameter:
#       path:           char    path for the input file
#       outPath:        char    path for the output files
#       isLeadingSort   int     use the 2nd of 3rd element as output data
#       isdbg           int     enable debug prints
"""

# Just use the cmd at the moment for test
path= sys.argv[1]
outPath = sys.argv[2]
isLeadingSort = int(sys.argv[3])
isdbg = int(sys.argv[4])

#outPath = os.getcwd()
#isLeadingSort = 0
#isdbg = 0

# define all the functions up front

def printStr(str):
    """ print when the debug option is set """
    if isdbg:
        print (str)

def testPath(path):
    """raise an exception if we cant find the path or file"""
    if not os.path.exists(path):
        raise Exception ('File not found: ' + path )
        return false


#
# This is where we start
#
# check that the paths exist or raise an exception

testPath(path)
testPath(outPath)

printStr ('paths ok')

#init
arline = []
fnameOut = chr(1) # init the output filename
line=object()
fOut=object()


# open the input file for reading and process though in a loop
with open(path,'r') as f:
    for line in f:
        printStr( 'for line in f: ' )

        if isLeadingSort:
            wrds=2
        else:
            wrds=1
        arLine = re.split('[ \n]+',line,wrds)
        newFname = arLine[0]
        outLine = arLine[len(arLine)-1]

        if newFname == fnameOut:
            printStr ('writing to open file: ' + fnameOut)  
        else:
            fnameOut = newFname
            printStr ('opennextfile: ' + fnameOut + '- closing: ' + str(fOut) )
            try:
                fOut.close()
            except:
                pass

            if fnameOut in ('' , '\n'):
                raise Exception ('Filename is not the first element of the data: '  ) 
            fOut = open(os.path.join(outPath,fnameOut),'w') # open new

        #write
        fOut.write(outLine)

    try:
        fOut.close()
    except:
        pass


print ( 'timediff : ' + str(time() - t))
4

0 に答える 0