GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time · Issue #603 · GoogleCloudPlatform/java-docs-samples

Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time #603

New issue
Copy link
New issue
Copy link
Closed
Closed
Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time#603
Copy link

Description

@grantespo
grantespo
opened on Apr 8, 2017
Issue body actions

In my Main Activity, I initialize the Translate variable. If you look at the logs: I track when the initialization starts and when it finishes. Most of the time it initializes quick. But 1/5 times it takes up to 30 seconds to 3 minutes (UNACCEPTABLE).

    AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {

        @Override
        public void onPostExecute (Void aVoid) {

            Log.i("APP", "finished");

        }

        @Override
        protected Void doInBackground(Void... voids) {
            Log.i("APP", "start");
          Translate  translate = TranslateOptions.newBuilder().setApiKey("XXXXX-ZZZZZ").build().getService();
            return null;
        }

    };
    asyncTask.execute();

I also have the latest versions in gradle:

   compile ('com.google.cloud:google-cloud-translate:0.11.0-alpha')
  compile ('com.google.apis:google-api-services-translate:v2-rev49-1.22.0')

Activity

  1. grantespo
    changed the title [-]translate2 = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time[/-] [+]Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time[/+] on Apr 8, 2017
  2. lesv commented on Apr 22, 2017

    @lesv
    lesv
    on Apr 22, 2017
    Contributor
    More actions

    Totally agree with you. 3 minutes is unacceptable. Shouldn't you create the Translate object only once at startup?

    Where are you running this?

    I'll try to get you an answer, but this really should be a question for StackOverflow

    NOTE - You might wish to invalidate your ApiKey, and just change to xxxx when posting in the future.

  3. lesv commented on Apr 22, 2017

    @lesv
    lesv
    on Apr 22, 2017
    Contributor
    More actions

    Ah, found your SO Question and that your running on Android, so my comment is moot, though you might still wish to run a cloud service that initializates Translate and just request from that.

  4. lesv commented on Apr 22, 2017

    @lesv
    lesv
    on Apr 22, 2017
    Contributor
    More actions

    I'm sorry to say that if you look at the bottom of google-cloud-java, you note that "Android is not supported" for these libraries currently.

  5. lesv commented on Apr 22, 2017

    @lesv
    lesv
    on Apr 22, 2017
    Contributor
    More actions

    You might wish to use the REST interface instead.

  6. lesv
    closed this as completedon Apr 22, 2017
  7. grantespo commented on Apr 22, 2017

    @grantespo
    grantespo
    on Apr 22, 2017
    Author
    More actions

    How is it not supported on Android? I am using it in my production app right now and it translates messages good. It just takes a long time to initialize sometimes.

    I am initializing it in my Application class.

  8. lesv commented on Apr 22, 2017

    @lesv
    lesv
    on Apr 22, 2017
    Contributor
    More actions

    The engineering team hasn't had a chance to validate or optimize the library on Android so they asked that a warning be posted. I'm a bit surprised that it works at all -- there are files you might wish to change for Android such as excluding netty-borring-ssl-native and following the suggestion for TLS on Android.

    You might also wish to look at these examples. But as I said, we aren't testing on Android currently, so you are on your own. My apologies.

    That said, you will likely find that implementing with REST will produce a much smaller app and a much faster one.

    @GoogleCloudPlatform/gcloud FYI

  9. grantespo commented on Apr 22, 2017

    @grantespo
    grantespo
    on Apr 22, 2017
    Author
    More actions

    Will the team resume work? Is this library likely to stop working soon? Is it critical for me to transfer to REST API because I am actually happy with the performance right now.

  10. lesv commented on Apr 22, 2017

    @lesv
    lesv
    on Apr 22, 2017
    Contributor
    More actions

    There aren't any plans to break things. (and you can stay on a working version anyway) It's just surprising that it works on Android at all.

    REST might be the way to fix your 20% startup issues. (but I don't know the root cause). That's why I suggested it. Otherwise, it's really up to you.

  11. grantespo commented on Apr 23, 2017

    @grantespo
    grantespo
    on Apr 23, 2017
    Author
    More actions

    I appreciate your replies.

    My issue is never present the first time somebody opens my app. However, whenever somebody exits my app by pushing the back button, I call System.exit(0); then, after I immediately open the app again 50% of the time Translation API Initialization either delays or starts up immediately. I think the System.exit(0); plays a factor.

  12. lesv commented on Apr 23, 2017

    @lesv
    lesv
    on Apr 23, 2017
    Contributor
    More actions

    Ah - it sounds like the shutdown threads are left in a strange state. Take a look at this which suggests System.exit() isn't the best solution.

    I haven't written an Android app in several years, so I'm probably not thinking through everything. In the past, I've found this book to be invaluable.

    this.finish() may be a better choice. Again, the library hasn't been tested on Android, so you are on your own here. -- hope this helps.

  13. minherz
    added 6 commits that reference this issue on Nov 9, 2022

    deps: update dependency com.google.cloud:google-cloud-core to v1.96.0 (…

    4e28ba7

    chore: release 0.121.5 (#604)

    5fc0600

    deps: update dependency com.google.cloud:google-cloud-core to v1.96.0 (…

    255f83b

    chore: release 0.121.5 (#604)

    dfc38fd

    deps: update dependency com.google.cloud:google-cloud-core to v1.96.0 (…

    e4b4f54

    chore: release 0.121.5 (#604)

    632a31c
  14. Shabirmean
    added 2 commits that reference this issue on Nov 14, 2022

    deps: update dependency com.google.cloud:google-cloud-core to v1.95.3 (…

    3286a5a

    deps: update dependency com.google.cloud:google-cloud-core to v1.95.3 (…

    3f5fbd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.