今天的Appengine部署速度非常慢?

时间:2016-06-06 13:53:36

标签: google-app-engine gcloud google-managed-vm managed-vm

我们需要部署一个小型Java项目 它包括9000+个文件

命令:mvn gcloud:deploy

但是我得到了日志:

def create_order(request):
    LanguageLevelFormSet = formset_factory(LanguageLevelForm, extra=5, max_num=5)
    language_level_formset = LanguageLevelFormSet(request.POST or None)
    job_creation_form = JobCreationForm(request.POST or None, request.FILES or None)

    context = {'job_creation_form': job_creation_form,
               'formset': language_level_formset}

    if request.method == 'POST':
        if job_creation_form.is_valid() and language_level_formset.is_valid():
            cleaned_data_job_creation_form = job_creation_form.cleaned_data
            cleaned_data_language_level_formset = language_level_formset.cleaned_data

            context = {
                'cleaned_data_job_creation_form': cleaned_data_job_creation_form,
                "cleaned_data_language_level_formset": cleaned_data_language_level_formset,
            }
            mutable = request.POST._mutable # I'm adding parameter 'review' to be able to differ between two different posts in confirm_order view
            request.POST._mutable = True
            request.POST['review'] = True
            request.POST._mutable = mutable
            return confirm_order(request, context)
        else:
            return render(request, 'auth/jobs/create-job.html', context=context)
    return render(request, 'auth/jobs/create-job.html', context=context)


def confirm_order(request, context):
    print context
    cleaned_data_job_creation_form = context['cleaned_data_job_creation_form']
    cleaned_data_language_level_formset = context['cleaned_data_language_level_formset']
    print request.POST['review']
    if request.method == 'POST' and request.POST['review'] == True:

        file = cleaned_data_job_creation_form['file']
        count = 5 #simplified multiple rows
        jobs = []
        for language_level_form in [d for d in cleaned_data_language_level_formset if d]:
            language = language_level_form['language']
            level = language_level_form['level']
            d = {}
            d['language_from'] = cleaned_data_job_creation_form['language_from'].name
            d['language_to'] = language
            d['number_of_characters'] = count
            d['price_per_sign'] = 1
            d['estimated_price'] = count * d['price_per_sign']
            jobs.append(d)

        table = CreatedOrdersTable(jobs)
        context = {'table': table,
                   'cleaned_data_job_creation_form': cleaned_data_job_creation_form,
                   'cleaned_data_language_level_formset': cleaned_data_language_level_formset}
        return render(request, 'auth/jobs/confirm-order.html', context=context)
    else:
        for language_level_form in [d for d in cleaned_data_language_level_formset if d]:
            language = language_level_form['language']
            level = language_level_form['level']

            Job.objects.create(
                    customer=request.user,
                    text_to_translate=cleaned_data_job_creation_form['text_to_translate'],
                    file=cleaned_data_job_creation_form['file'],
                    short_description=cleaned_data_job_creation_form['short_description'],
                    notes=cleaned_data_job_creation_form['notes'],
                    language_from=cleaned_data_job_creation_form['language_from'],
                    language_to=language,
                    level=level,
            )
        return HttpResponseRedirect('/order-success')

每分钟约50分钟 所以它将花费180分钟......

这是非常缓慢的

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:4)

设置环境变量CLOUDSDK_APP_USE_GSUTIL=1并重试;这使用了一个不太可靠但速度更快的文件上传代码路径(有计划加快默认代码路径)。

答案 1 :(得分:3)

我们遇到同样的问题,但速度很慢。 猜猜我们已经解决了。

首先,我们跟踪了gcloud日志,发现很多文件已经上传,这些文件都没有修改过。因此,我们尝试跟踪gcloud的源代码,我们发现问题是由Google Cloud Storage JSON API"。

引起的。

当它查询Bucket列表时,它返回了1000个项目,但我们有1325项,所以我想我们发现了这个问题。

然后,我们查找api引用,并找到一个参数 - maxResults,因此我们尝试修改源代码(cloud_storage.py),当它的值超过1000时我们发现它没有效果。

最后,我们找到另一个参数 - nextPageToken,我们查询列表直到" nextPageToken"是没有,现在它得到了来自" Google云端存储"并且不再上传存在的文件。

def ListBucket(bucket_ref, client):
  request = STORAGE_MESSAGES.StorageObjectsListRequest(bucket=bucket_ref.bucket)

  items = set()
  try:
    response = client.objects.List(request)
    for item in response.items:
      items.add(item.name)
    while response.nextPageToken:
      request = STORAGE_MESSAGES.StorageObjectsListRequest(bucket=bucket_ref.bucket,pageToken=response.nextPageToken)
      response = client.objects.List(request)
      for item in response.items:
        items.add(item.name)
  except api_exceptions.HttpError as e:
    raise UploadError('Error uploading files: {e}'.format(e=e))

  return items