Configurar grupos de conexiones
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Configurar grupos de conexiones
Explora más
Para obtener documentación en la que se incluye esta muestra de código, consulta lo siguiente:
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content provides code examples in C++, Go, and Java demonstrating how to configure connection pools for Google Cloud Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eConnection pool size can be set to optimize the number of channels used for communication, with a size of 10 being used in the provided examples.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples show how to set the pool size when creating a Bigtable client using each respective language.\u003c/p\u003e\n"],["\u003cp\u003eSetting up Application Default Credentials (ADC) is necessary to authenticate with Bigtable, and instructions to do so are referenced.\u003c/p\u003e\n"],["\u003cp\u003eFor more resources on managing connection pools and installing client libraries, relevant links to the Bigtable documentation and sample browser are provided.\u003c/p\u003e\n"]]],[],null,["Configure connection pools\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Configure connection pools](/bigtable/docs/configure-connection-pools)\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace gc = ::google::cloud;\n [](std::string const& project_id, std::string const& instance_id,\n std::string const& table_id) {\n auto constexpr kPoolSize = 10;\n auto options = gc::Options{}.set\u003cgc::GrpcNumChannelsOption\u003e(kPoolSize);\n cbt::Table table(cbt::MakeDataConnection(options),\n cbt::TableResource(project_id, instance_id, table_id));\n std::cout \u003c\u003c \"Connected with channel pool size of \" \u003c\u003c kPoolSize \u003c\u003c \"\\n\";\n }\n\nGo\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \t\"cloud.google.com/go/bigtable\"\n \t\"google.golang.org/api/option\"\n )\n\n func configureConnectionPool(w io.Writer, projectID, instanceID string) error {\n \t// projectID := \"my-project-id\"\n \t// instanceID := \"my-instance-id\"\n \tctx := context.Background()\n\n \t// Set up Bigtable data operations client.\n \tpoolSize := 10\n \tclient, err := bigtable.https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigtable/latest/index.html#cloud_google_com_go_bigtable_Client_NewClient(ctx, projectID, instanceID, option.WithGRPCConnectionPool(poolSize))\n \tdefer client.Close()\n\n \tif err != nil {\n \t\treturn fmt.Errorf(\"bigtable.NewClient: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Connected with pool size of %d\", poolSize)\n\n \treturn nil\n }\n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.api.gax.grpc.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html;\n import com.google.cloud.bigtable.data.v2.https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataClient.html;\n import com.google.cloud.bigtable.data.v2.https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html;\n import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;\n import java.io.IOException;\n\n public class ConfigureConnectionPool {\n\n public static void configureConnectionPool(String projectId, String instanceId) {\n // String projectId = \"my-project-id\";\n // String instanceId = \"my-instance-id\";\n\n https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html.Builder settingsBuilder =\n https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html.newBuilder().https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_Builder_setProjectId_java_lang_String_(projectId).https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_Builder_setInstanceId_java_lang_String_(instanceId);\n\n settingsBuilder\n .https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_Builder_stubSettings__()\n .setTransportChannelProvider(\n EnhancedBigtableStubSettings.defaultGrpcTransportProviderBuilder()\n .https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.Builder.html#com_google_api_gax_grpc_InstantiatingGrpcChannelProvider_Builder_setPoolSize_int_(10)\n .build());\n\n https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html settings = settingsBuilder.build();\n try (https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataClient.html dataClient = https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataClient.html.create(settings)) {\n https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html provider =\n (https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html)\n settings.https://cloud.google.com/java/docs/reference/google-cloud-bigtable/latest/com.google.cloud.bigtable.data.v2.BigtableDataSettings.html#com_google_cloud_bigtable_data_v2_BigtableDataSettings_getStubSettings__().getTransportChannelProvider();\n\n int poolSize = provider.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.html#com_google_api_gax_grpc_InstantiatingGrpcChannelProvider_toBuilder__().https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.Builder.html#com_google_api_gax_grpc_InstantiatingGrpcChannelProvider_Builder_getPoolSize__();\n\n System.out.println(String.format(\"Connected with pool size of %d\", poolSize));\n } catch (IOException e) {\n System.out.println(\"Error during ConfigureConnectionPool: \\n\" + e.toString());\n }\n }\n }\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]