读取很多txt文件的最佳解决方案是什么 [英] What is best solution for read alot of txt file

查看:103
本文介绍了读取很多txt文件的最佳解决方案是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
服务器中有大约200个.txt文件,每个文件大约有20个。这些文件每10秒更改一次。每个文件的容量大约是250字节。



i希望使用主题绘制图表或计算或...每10秒



什么是这个场景的最佳和最快的解决方案?



我应该在线阅读主题并保存数组中的每个文件数量?

我想使用10个线程,每个线程读取20个文件,并将文件内容保存在一行数组中。这是真的吗?

如果我这样做,我可以用另一个线程同时读取这个数组吗?



我是什么尝试过:



i想要使用10个线程,每个线程读取20个文件,并在一行数组中保存文件内容

hi there is about 200 .txt file in a server , every file have about 20 number. these files change every 10 second. capacity of each file is about 250 byte.

i want to use theme for draw a chart or calculating or ...every 10 second

what is best and fastest solution for this scenario ?

should i read theme online and save every number of files in a array ?
i want to use 10 thread and each thread read 20 files and save content of a file in one line of array . is it true ?
if i do this, can i read this array in same time with another thread ?

What I have tried:

i want to use 10 thread and each thread read 20 files and save content of a file in one line of array

推荐答案

作为考虑多线程方法时的一般经验法则,请考虑线程中是否存在可从并行化中受益的延迟。



在这种情况下,我怀疑你在等待文件更改的等待时间是你的延迟。



性能更好的模型是要执行以下操作。



1.使用目录/文件监视机制,在发生更改/新文件时报告,在事件中不执行任何操作而不是设置数组中文件项上的脏标志。

2.有一个线程检查脏项,然后从文件中读取它们。

3.有一个渲染线程,a)将你的数组复制到第二个渲染数组b)从渲染数组渲染图表



在你想要的所有点上最小化线程争用可能发生的时间,并尽可能使用事件驱动的机制。
As a general rule of thumb when considering a multi-threaded approach, consider if there is any latency in the thread that would benefit from parallelization.

In this case I suspect that you are thinking the wait time while waiting for a file to change is your latency.

A better performing model is to do the following.

1. Use a directory / file watching mechanism which reports changed/new files when they occur, do nothing in the event OTHER than set the dirty flag on the file item in your array.
2. Have a single thread that checks for dirty items, and then reads them from their file.
3. Have a render thread which a) copies your array to a second render array b) renders the chart from the render array

At all points you want to minimize the amount of time thread contention can occur, and use event driven mechanics where possible.


这篇关于读取很多txt文件的最佳解决方案是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆