Google지도 지오 코딩 API를 사용하는 ASP.NET MVC 응용 프로그램에서 작업하고 있습니다. 단일 배치에서 Geocoding API에 제출할 쿼리가 1000 개까지있을 수 있으므로 성능을 향상시키는 병렬 처리 방식을 사용하려고합니다. 각 코어에 대한 프로세스를 시작 담당하는 방법은 다음과 같습니다원격 응용 프로그램에 스로틀 병렬 요청
public void GeoCode(Queue<Job> qJobs, bool bolKeepTrying, bool bolSpellCheck, Action<Job, bool, bool> aWorker)
{
// Get the number of processors, initialize the number of remaining
// threads, and set the starting point for the iteration.
int intCoreCount = Environment.ProcessorCount;
int intRemainingWorkItems = intCoreCount;
using(ManualResetEvent mreController = new ManualResetEvent(false))
{
// Create each of the work items.
for(int i = 0; i < intCoreCount; i++)
{
ThreadPool.QueueUserWorkItem(delegate
{
Job jCurrent = null;
while(qJobs.Count > 0)
{
lock(qJobs)
{
if(qJobs.Count > 0)
{
jCurrent = qJobs.Dequeue();
}
else
{
if(jCurrent != null)
{
jCurrent = null;
}
}
}
aWorker(jCurrent, bolKeepTrying, bolSpellCheck);
}
if(Interlocked.Decrement(ref intRemainingWorkItems) == 0)
{
mreController.Set();
}
});
}
// Wait for all threads to complete.
mreController.WaitOne();
}
}
이것은 내가 Microsoft's parallel computing web site에서 발견 패턴 문서를 기반으로합니다. 문제는 Google API가 10 QPS (기업 고객)의 한계를 가지고 있다는 것입니다. 그 중 하나는 HTTP 403 오류입니다. 이 방법은 병렬 처리의 이점을 누릴 수 있지만 내가 만드는 요청을 제한하는 방법입니까? Thread.Sleep 사용하여 시도했지만 문제가 해결되지 않습니다. 어떤 도움이나 제안이라도 대단히 감사하겠습니다.
덕분에 -이 나를 다른 문제에 대해 생각을 가지고있다. – markpirvine