最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何提高线速度?

SEO心得admin89浏览0评论
本文介绍了如何提高线速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用这个代码 但它很慢并且使用更多cpu 所以 i想要更快的方式 但我怎么做呢? (我想要一箱饼干。因此我需要很多线程) 我的代码

public void Start() { for ( int i = 1 ; i < 150 ; i ++) { Thread reqThread = new 线程( new ParameterizedThreadStart(Test)); reqThread.Start(i); } } 公共 void 测试( object i) { 尝试{ SetProxy 连接发送回复} catch { Test(i)} }

解决方案

从线程速度开始是一个相对的概念,取决于你的CPU(从复杂的处理开始150个线程)可能很麻烦,少就多了!)。 一般来说,糟糕的线程逻辑很容易导致应用程序变慢......以及一些奇怪的异常。 当我看着你的例子时会想到三件事_ 1。 测试方法跳出来真的很糟糕。 在catch块中你没有处理异常,你只是递归地重复调用 Test 方法,可以导致(半)无限循环。 2。如果你是网络爬虫,那么网络速度可能是一个因素。 3。也许在线程之间存在共享资源(属性),这些资源没有正确共享或锁定太长。 使用 perfmon 工具,用于查明应用程序中的瓶颈。 好运气!

I use this code but it is slow and use more cpu so i want faster way but how i can do it? ( i want crate a cracker. becasue of this i need much thread ) my code

public void Start() { for (int i = 1; i < 150; i++) { Thread reqThread = new Thread(new ParameterizedThreadStart(Test)); reqThread.Start(i); } } Public void Test ( object i) { Try{ SetProxy Connect Send Response } catch { Test(i) } }

解决方案

To begin with thread speed is an relative concept and depends on your CPU (starting 150 threads with complex processing can be cumbersome, less is more!). In general, bad threading logic can easily result in slowing down application... and to some odd exceptions. Three things come to mind when I look at you example_ 1. Test method jumps out as really bad. Inside catch block you don't handle exception, you just recursively repeat call to Test method, that can result in (semi-)endless loop. 2. If by cracker you mean web crawler then network speed can be a factor. 3. Perhaps there are shared resources (properties) between threads which aren't properly shared or are locked too long. Use perfmon tool for pinpointing bottlenecks in you application. Good luck!

发布评论

评论列表(0)

  1. 暂无评论