在ASP.net网站中搜索文件的优化和有效方式是什么? [英] What is the optimized and efficient way of searching files in ASP.net website?

查看:82
本文介绍了在ASP.net网站中搜索文件的优化和有效方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在开发一个网站,必须在其中提供搜索功能
位于两个给定路径(例如"D:\ MyWeb1 \"和"D:\ MyWeb2")的文件.

我在网上搜索后发现以下代码段

Hi All

I am developing a website in which I have to provide a feature to serach
files which are at two given paths (say "D:\MyWeb1\" and "D:\MyWeb2").

I searched on net and found below code snippet

void DirSearch(string sDir)
{
    try
    {
       foreach (string d in Directory.GetDirectories(sDir))
       {
        foreach (string f in Directory.GetFiles(d, txtFile.Text))
        {
           lstFilesFound.Items.Add(f);
        }
        DirSearch(d);
       }
    }
    catch (System.Exception excpt)
    {
        Console.WriteLine(excpt.Message);
    }
}



在其中一个站点上,我遇到了代码,该代码创建了两个线程以在两个文件夹中进行搜索,然后组合结果以进行快速搜索.
然后我想到了几个问题
1.在ASP.net网站中创建线程以搜索文件是否很好?
2.如果进行搜索的用户数量增加,将会发生什么
网站的性能如何?
3.我应该使用AJAX来实现它吗?
4.有没有更好的方法来搜索ASP.net网站的文件?

请提出一种在ASP.net网站上搜索文件的方法.

在此先感谢:)

SK



And on one of the sites I came across code which created two threads to search in two folders and then combine the results for fast searching.
And then few question came up in my mind
1. Is it good to make threads in ASP.net website to search in files?
2. If the number of users making the search increases what will happen
to the performance of my site?
3. SHould I implement it using AJAX?
4. Is there any better way to search in a file for ASP.net website?

Please suggest a approach for searching a file in ASP.net website.

Thanks in advance :)

THE SK

推荐答案

尝试回答有关进一步搜索优化的后续问题:

进一步的优化并非无关紧要.它可以是语义感知的.

例如,您可以使用有关最受欢迎请求的统计信息来部分索引某些搜索结果.当您收集到足够的统计信息时,您可以从索引中的查找开始响应,该索引应使用字典功能的原理,但应基于磁盘内存来实现.您的服务可以使用一些不那么忙碌的时间来运行用于更新索引数据的特殊优化线程.这只是一个主意.

我认为高级优化是一个非常艰苦的竞争,所以我猜想,一些最佳的优化方案是保密的.它可能需要大量的研究和实验工作.

—SA
Trying to answer a follow-up Question on further search optimization:

Further optimization is not trivial. It can be semantic-aware.

For example, you could partially index some of your search results using statistics on most popular requests. When you collect enough statistics you can start response from look-up in your index, which should use the principles of dictionary functionality but implemented based on disk memory. You service could use some of less busy time running a special optimization thread used to update the indexed data. This is just one idea.

I think the advanced optimization is a matter of very hard competition, so I would guess, some best optimization schema are kept in secret. It may need a good deal of research and perhaps experimental work.

—SA


1)您绝对需要线程,每次搜索至少需要一个单独的线程.如果您有多个内核或CPU,并且没有太多并行工作的客户端,则将单个搜索分为多个并行的子目录将缩短最终响应时间.

2)显然,情况并没有好转.您的CPU时间分为更多任务.请参阅以上项目.一个重要的警告:不要让线程的数量与用户会话的数量成比例地增长.使线程数有限且可预测,否则太多线程将使您的服务器不堪一击:-).如果线程数可变,请使用线程池.实际上,您甚至可以保持固定数量的线程.如果某些线程不忙,它们可能停留在阻塞调用,例如EventWaitHandle并等待下一个任务.

3)可能,但是要视情况而定.这取决于您在做什么.如果请求不是很快,但是响应却需要时间(搜索的典型情况),那么您可以轻松地仅使用普通形式的POST即可.

4)参见项目(1).另外,我对Directory.GetFiles大警告:请参见 ^ ],讨论和解决方法.彻底做.

请参阅我的其他答案.

祝你好运.
—SA
1) You absolutely need threads, at least one separate thread per search. By if you have many cores or CPUs and not too many clients working in parallel, splitting a single search into sub-directories for more parallelism will improve final response time.

2) Not getting better, apparently. You CPU time is divided into more tasks. See the above item. One big warning: do not make the number of your threads growing proportionally to the number of user sessions. Make number of thread limited and predictable, otherwise too many thread will blow you server :-). Use thread pool if the number of threads is variable. In fact, you can even keep fixed number of threads, too. If some threads are not busy, they may stay at the blocking call to, say, EventWaitHandle and wait for next task.

3) Probably, but it depends. It depends on what you''re doing. If the request is not very quick but response takes time (a typical case for search), you may easily go away with just a POST from a normal form.

4) See item (1). Also, I have a big warning about Directory.GetFiles: see Directory.Get.Files search pattern problem[^], the discussion and work-around. Do it thoroughly.

Please see my other Answer.

Good luck.
—SA


这篇关于在ASP.net网站中搜索文件的优化和有效方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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