{"id":812,"date":"2024-01-27T21:13:24","date_gmt":"2024-01-27T12:13:24","guid":{"rendered":"https:\/\/itstudy365.com\/blog\/?page_id=812"},"modified":"2024-02-18T17:24:47","modified_gmt":"2024-02-18T08:24:47","slug":"cassandra-practice","status":"publish","type":"page","link":"https:\/\/itstudy365.com\/blog\/cassandra-practice\/","title":{"rendered":"Cassandra 3.11.9 Practice"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"686\" src=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/01\/Cassandra_logo.svg_-1024x686.png\" alt=\"\" class=\"wp-image-813\" style=\"aspect-ratio:1.4927113702623906;width:234px;height:auto\" srcset=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/01\/Cassandra_logo.svg_-1024x686.png 1024w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/01\/Cassandra_logo.svg_-300x201.png 300w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/01\/Cassandra_logo.svg_-768x515.png 768w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/01\/Cassandra_logo.svg_.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The target Cassandra version is 3.11.9<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >\u76ee\u6b21<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step1Create_a_docker-composeyml_of_cassandra\" title=\"Step1.Create a docker-compose.yml of cassandra\">Step1.Create a docker-compose.yml of cassandra<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step2Start_Cassandra_with_docker_environment\" title=\"Step2.Start Cassandra with docker environment\">Step2.Start Cassandra with docker environment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step3Use_cqlsh_to_connect_to_the_Cassandra_container\" title=\"Step3.Use cqlsh to connect to the Cassandra container\">Step3.Use cqlsh to connect to the Cassandra container<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step4_Create_keyspace_and_table_for_sample_data\" title=\"Step4. Create keyspace and table for sample data\">Step4. Create keyspace and table for sample data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step5_Learn_about_querying_data_in_Cassandra_using_CQL\" title=\"Step5. Learn about querying data in Cassandra using CQL\">Step5. Learn about querying data in Cassandra using CQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step6_Explore_how_indexing_works_in_Cassandra\" title=\"Step6. Explore how indexing works in Cassandra\">Step6. Explore how indexing works in Cassandra<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step7_Experiment_with_different_consistency_levels\" title=\"Step7. Experiment with different consistency levels\">Step7. Experiment with different consistency levels<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step8_Explore_tools_and_techniques_for_monitoring_Cassandra_performance\" title=\"Step8. Explore tools and techniques for monitoring Cassandra performance\">Step8. Explore tools and techniques for monitoring Cassandra performance<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#1Use_nodetool_command_to_see_the_status\" title=\"1.Use nodetool command to see the status\">1.Use nodetool command to see the status<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Displays_the_status_of_the_nodes_in_the_cluster\" title=\"Displays the status of the nodes in the cluster.\">Displays the status of the nodes in the cluster.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#2Use_nodetool_command_to_see_various_metrics\" title=\"2.Use nodetool command to see various metrics\">2.Use nodetool command to see various metrics<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Detailed_information_about_the_current_node_in_the_Cassandra_cluster\" title=\"Detailed information about the current node in the Cassandra cluster.\">Detailed information about the current node in the Cassandra cluster.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Information_about_the_thread_pools_and_message_types_processed_by_the_Cassandra_node\" title=\"Information about the thread pools and message types processed by the Cassandra node\">Information about the thread pools and message types processed by the Cassandra node<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Statistics_about_a_specific_column_family_table_in_a_keyspace\" title=\"Statistics about a specific column family (table) in a keyspace.\">Statistics about a specific column family (table) in a keyspace.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Information_about_garbage_collection_GC_statistics_for_the_Cassandra_node\" title=\"Information about garbage collection (GC) statistics for the Cassandra node\">Information about garbage collection (GC) statistics for the Cassandra node<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Compaction_tasks_that_are_pending_or_in_progress_on_the_Cassandra_node\" title=\"Compaction tasks that are pending or in progress on the Cassandra node\">Compaction tasks that are pending or in progress on the Cassandra node<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#3Use_nodetool_command_to_monitor_query_performance\" title=\"3.Use nodetool command to monitor query performance\">3.Use nodetool command to monitor query performance<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Histograms_of_latency_metrics_for_different_types_of_operations_served_by_the_proxy_layer_of_Cassandra\" title=\"Histograms of latency metrics for different types of operations served by the proxy layer of Cassandra.\">Histograms of latency metrics for different types of operations served by the proxy layer of Cassandra.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Histograms_of_various_metrics_related_to_the_specified_table\" title=\"Histograms of various metrics related to the specified table.\">Histograms of various metrics related to the specified table.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Individual_client_sessions_that_have_been_traced\" title=\"Individual client sessions that have been traced\">Individual client sessions that have been traced<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step9_How_to_specify_the_heap_size\" title=\"Step9. How to specify the heap_size\">Step9. How to specify the heap_size<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step10_How_to_specify_the_Concurrent_Reads_and_Writes_Parameters\" title=\"Step10. How to specify the Concurrent Reads and Writes Parameters\">Step10. How to specify the Concurrent Reads and Writes Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step11_How_to_specify_the_Compaction_Strategy\" title=\"Step11. How to specify the Compaction Strategy\">Step11. How to specify the Compaction Strategy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step12_How_to_specify_the_Memtable_Configuration\" title=\"Step12. How to specify the Memtable Configuration\">Step12. How to specify the Memtable Configuration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step13_How_to_specify_the_Cache_Configuration\" title=\"Step13. How to specify the Cache Configuration\">Step13. How to specify the Cache Configuration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step14_How_to_specify_the_Native_Transport_Configuration\" title=\"Step14. How to specify the Native Transport Configuration\">Step14. How to specify the Native Transport Configuration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/itstudy365.com\/blog\/cassandra-practice\/#Step15_Learn_about_authentication_and_authorization\" title=\"Step15. Learn about authentication and authorization\">Step15. Learn about authentication and authorization<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step1Create_a_docker-composeyml_of_cassandra\"><\/span>Step1.Create a docker-compose.yml of cassandra<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Download repository to practice<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ git clone https:\/\/github.com\/blueskyarea\/cassandra-practice.git<\/code><\/pre><\/div>\n\n\n\n<p>2.Check the content of the Dockerfile &amp; docker-compose file<\/p>\n\n\n\n<p>Dockerfile<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ cat cassandra-practice\/cassandra-docker\/Dockerfile\n# Use the official Cassandra image as the base image\nFROM cassandra:3.11.9\n\n# Install vim\nRUN apt-get update && apt-get install -y vim\n\n# Set the default command to run when the container starts\nCMD [&quot;cassandra&quot;, &quot;-f&quot;]<\/code><\/pre><\/div>\n\n\n\n<p>docker-compose.yml<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ cat cassandra-practice\/cassandra-docker\/docker-compose.yml\ncassandra-node1:\n    build:\n      context: .\n      dockerfile: Dockerfile\n    container_name: cassandra-node1\n    environment:\n        - CASSANDRA_CLUSTER_NAME=MyCluster\n        - CASSANDRA_SEEDS=cassandra-node1,cassandra-node2\n        - CASSANDRA_DC=se1\n        - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch\n    ports:\n        - &quot;9042:9042&quot;\n    volumes:\n        - .\/cassandra-node1-data:\/var\/lib\/cassandra\n---(omit)---<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li>Docker image version is 3.11.9 that is specified in Dockerfile.<\/li>\n\n\n\n<li>Specified container name with &#8220;<code>cassandra-node1<\/code>&#8220;.<\/li>\n\n\n\n<li>Specified some environment variables.<\/li>\n\n\n\n<li>Specified port number.<\/li>\n\n\n\n<li>Specified volume to save data persist.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step2Start_Cassandra_with_docker_environment\"><\/span>Step2.Start Cassandra with docker environment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Download Docker image of Cassandra and start the container<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ cd cassandra-practice\/cassandra-docker\/\n$ docker-compose up -d\n-- Output Example --\nPulling cassandra-node1 (cassandra:3.11.9)\u2026\n....\nCreating cassandra-node1 \u2026 done\nCreating cassandra-node2 \u2026 done\nCreating cassandra-node3 \u2026 done\n-----------------------<\/code><\/pre><\/div>\n\n\n\n<p>2.Check the running process<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker ps\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\nb8d95cbdbb15 cassandra:3.11.9 &quot;docker-entrypoint.s\u2026&quot; 12 minutes ago Up 12 minutes 7000-7001\/tcp, 7199\/tcp, 9160\/tcp, 0.0.0.0:9044-&gt;9042\/tcp, :::9044-&gt;9042\/tcp cassandra-node3\n93fd9d7b458a cassandra:3.11.9 &quot;docker-entrypoint.s\u2026&quot; 12 minutes ago Up 12 minutes 7000-7001\/tcp, 7199\/tcp, 9160\/tcp, 0.0.0.0:9043-&gt;9042\/tcp, :::9043-&gt;9042\/tcp cassandra-node2\n5ceb8b7b3dd3 cassandra:3.11.9 &quot;docker-entrypoint.s\u2026&quot; 12 minutes ago Up 12 minutes 7000-7001\/tcp, 7199\/tcp, 9160\/tcp, 0.0.0.0:9042-&gt;9042\/tcp, :::9042-&gt;9042\/tcp cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step3Use_cqlsh_to_connect_to_the_Cassandra_container\"><\/span>Step3.Use <code>cqlsh<\/code> to connect to the Cassandra container<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Start the cqlsh from 1 container (it may take time until possible to execute)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 cqlsh\nConnected to MyCluster at 127.0.0.1:9042.\n[cqlsh 5.0.1 | Cassandra 3.11.9 | CQL spec 3.4.4 | Native protocol v4]\nUse HELP for help.\ncqlsh&gt;<\/code><\/pre><\/div>\n\n\n\n<p>2.Check the HELP<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; HELP\n\nDocumented shell commands:\n===========================\nCAPTURE  CLS          COPY  DESCRIBE  EXPAND  LOGIN   SERIAL  SOURCE   UNICODE\nCLEAR    CONSISTENCY  DESC  EXIT      HELP    PAGING  SHOW    TRACING\n\nCQL help topics:\n================\nAGGREGATES               CREATE_KEYSPACE           DROP_TRIGGER      TEXT\nALTER_KEYSPACE           CREATE_MATERIALIZED_VIEW  DROP_TYPE         TIME\nALTER_MATERIALIZED_VIEW  CREATE_ROLE               DROP_USER         TIMESTAMP\nALTER_TABLE              CREATE_TABLE              FUNCTIONS         TRUNCATE\nALTER_TYPE               CREATE_TRIGGER            GRANT             TYPES\nALTER_USER               CREATE_TYPE               INSERT            UPDATE\nAPPLY                    CREATE_USER               INSERT_JSON       USE\nASCII                    DATE                      INT               UUID\nBATCH                    DELETE                    JSON\nBEGIN                    DROP_AGGREGATE            KEYWORDS\nBLOB                     DROP_COLUMNFAMILY         LIST_PERMISSIONS\nBOOLEAN                  DROP_FUNCTION             LIST_ROLES\nCOUNTER                  DROP_INDEX                LIST_USERS\nCREATE_AGGREGATE         DROP_KEYSPACE             PERMISSIONS\nCREATE_COLUMNFAMILY      DROP_MATERIALIZED_VIEW    REVOKE\nCREATE_FUNCTION          DROP_ROLE                 SELECT\nCREATE_INDEX             DROP_TABLE                SELECT_JSON<\/code><\/pre><\/div>\n\n\n\n<p>3.exit the cqlsh<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; exit<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step4_Create_keyspace_and_table_for_sample_data\"><\/span>Step4. Create keyspace and table for sample data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Create a keyspace<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 cqlsh<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; CREATE KEYSPACE myblog WITH replication = {&#39;class&#39;: &#39;SimpleStrategy&#39;, &#39;replication_factor&#39;: 3};<\/code><\/pre><\/div>\n\n\n\n<p>A replication strategy of <code>SimpleStrategy<\/code> and a replication factor of <code>3<\/code>.<br>This means that each piece of data will be replicated to three nodes in the cluster for fault tolerance.<\/p>\n\n\n\n<p>2.Create a table<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; CREATE TABLE myblog.posts (id UUID PRIMARY KEY, title TEXT, content TEXT, author TEXT);<\/code><\/pre><\/div>\n\n\n\n<p>3.Insert a sample data<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; INSERT INTO myblog.posts (id, title, content, author) VALUES (uuid(), &#39;First blog&#39;, &#39;My blog&#39;, &#39;John&#39;);<\/code><\/pre><\/div>\n\n\n\n<p>4.Select records from the table<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; SELECT * FROM myblog.posts;\n\n id                                   | author | content | title\n--------------------------------------+--------+---------+------------\n 74de1f36-8749-49f9-a5c1-de69832ea80f |   John | My blog | First blog\n\n(1 rows)<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step5_Learn_about_querying_data_in_Cassandra_using_CQL\"><\/span>Step5. Learn about querying data in Cassandra using CQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Try to shows a table&nbsp;information for a single&nbsp;table(This will fail)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; DESCRIBE TABLE posts;\nNo keyspace specified and no current keyspace<\/code><\/pre><\/div>\n\n\n\n<p>2.Connects the client session to a keyspace<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; USE myblog;<\/code><\/pre><\/div>\n\n\n\n<p>3.Shows a executable&nbsp;<em>CQL<\/em>&nbsp;information for a single&nbsp;table(This will success)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; DESCRIBE TABLE posts;\n\nCREATE TABLE myblog.posts (\n    id uuid PRIMARY KEY,\n    author text,\n    content text,\n    title text\n) WITH bloom_filter_fp_chance = 0.01\n    AND caching = {&#39;keys&#39;: &#39;ALL&#39;, &#39;rows_per_partition&#39;: &#39;NONE&#39;}\n    AND comment = &#39;&#39;\n    AND compaction = {&#39;class&#39;: &#39;org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy&#39;, &#39;max_threshold&#39;: &#39;32&#39;, &#39;min_threshold&#39;: &#39;4&#39;}\n    AND compression = {&#39;chunk_length_in_kb&#39;: &#39;64&#39;, &#39;class&#39;: &#39;org.apache.cassandra.io.compress.LZ4Compressor&#39;}\n    AND crc_check_chance = 1.0\n    AND dclocal_read_repair_chance = 0.1\n    AND default_time_to_live = 0\n    AND gc_grace_seconds = 864000\n    AND max_index_interval = 2048\n    AND memtable_flush_period_in_ms = 0\n    AND min_index_interval = 128\n    AND read_repair_chance = 0.0\n    AND speculative_retry = &#39;99PERCENTILE&#39;;<\/code><\/pre><\/div>\n\n\n\n<p>4.Insert another sample data<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;Second blog&#39;, &#39;Hello&#39;, &#39;Mila&#39;);<\/code><\/pre><\/div>\n\n\n\n<p>5.Select records from the table<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; SELECT * FROM posts;\n\n id                                   | author | content | title\n--------------------------------------+--------+---------+-------------\n 74de1f36-8749-49f9-a5c1-de69832ea80f |   John | My blog |  First blog\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |   Mila |   Hello | Second blog\n\n(2 rows)<\/code><\/pre><\/div>\n\n\n\n<p>6.Select records from the table by column value(This will fail)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; SELECT * FROM posts WHERE author = &#39;Mila&#39;;\n\nInvalidRequest: Error from server: code=2200 [Invalid query] message=&quot;Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING&quot;<\/code><\/pre><\/div>\n\n\n\n<p>7.Select records from the table by id(This will success)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Please input the id instead of ???\nSELECT * FROM posts WHERE id = ???;\n\nEx)\ncqlsh:myblog&gt; SELECT * FROM posts WHERE id = 6f2a5531-85a8-4317-8459-2c3e94e38bc5;\n\n id                                   | author | content | title\n--------------------------------------+--------+---------+-------------\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |   Mila |   Hello | Second blog\n\n(1 rows)<\/code><\/pre><\/div>\n\n\n\n<p>8.Select records from the table by column value with &#8216;ALLOW FILTERING'(This will success)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; SELECT * FROM posts WHERE author = &#39;Mila&#39; ALLOW FILTERING;\n\n id                                   | author | content | title\n--------------------------------------+--------+---------+-------------\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |   Mila |   Hello | Second blog\n\n(1 rows)<\/code><\/pre><\/div>\n\n\n\n<p>9.Update a record<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Please input the id instead of ???\ncqlsh:myblog&gt; UPDATE posts SET content = &#39;Updated!&#39; WHERE id = ???;\n\nEx)\ncqlsh:myblog&gt; UPDATE posts SET content = &#39;Updated!&#39; WHERE id = 74de1f36-8749-49f9-a5c1-de69832ea80f;\n\n# And check the updated record\ncqlsh:myblog&gt; SELECT * FROM posts;\n\nEx)\ncqlsh:myblog&gt; SELECT * FROM posts;\n\n id                                   | author | content  | title\n--------------------------------------+--------+----------+-------------\n 74de1f36-8749-49f9-a5c1-de69832ea80f |   John | Updated! |  First blog\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |   Mila |    Hello | Second blog\n\n(2 rows)<\/code><\/pre><\/div>\n\n\n\n<p>10.Delete a record<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Please input the id instead of ???\ncqlsh:myblog&gt; DELETE FROM posts WHERE id = ???;\n\nEx)\ncqlsh:myblog&gt; DELETE FROM posts WHERE id = 74de1f36-8749-49f9-a5c1-de69832ea80f;\n\n# And check the deleted record\ncqlsh:myblog&gt; SELECT * FROM posts;\n\nEx)\ncqlsh:myblog&gt; SELECT * FROM posts;\n\n id                                   | author | content | title\n--------------------------------------+--------+---------+-------------\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |   Mila |   Hello | Second blog\n\n(1 rows)<\/code><\/pre><\/div>\n\n\n\n<p>11.Execute multiple SQL statement together<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Please input the id instead of ???\ncqlsh:myblog&gt; BEGIN BATCH\nINSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;Third blog&#39;, &#39;I&#39;&#39;m back&#39;, &#39;John&#39;);\nUPDATE posts SET content = &#39;Good night.&#39; WHERE id = ???;\nAPPLY BATCH;\n\nEx)\ncqlsh:myblog&gt; BEGIN BATCH\n          ... INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;Third blog&#39;, &#39;I&#39;&#39;m back&#39;, &#39;John&#39;);\n          ... UPDATE posts SET content = &#39;Good night.&#39; WHERE id = 6f2a5531-85a8-4317-8459-2c3e94e38bc5;\n          ... APPLY BATCH;\n\n# Check the updates result\ncqlsh:myblog&gt; SELECT * FROM posts;\n\n id                                   | author | content     | title\n--------------------------------------+--------+-------------+-------------\n 6502fc83-c78d-49d9-8928-79a83cc6eb70 |   John |    I&#39;m back |  Third blog\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |   Mila | Good night. | Second blog\n\n(2 rows)<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step6_Explore_how_indexing_works_in_Cassandra\"><\/span>Step6. Explore how indexing works in Cassandra<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Create Index<br>Create an index on the column you want to query.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; CREATE INDEX ON posts (title);<\/code><\/pre><\/div>\n\n\n\n<p>2.Query data<br>You can now query the data based on the indexed column.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; SELECT * FROM posts WHERE title = &#39;Third blog&#39;;\n\n id                                   | author | content  | title\n--------------------------------------+--------+----------+------------\n 6502fc83-c78d-49d9-8928-79a83cc6eb70 |   John | I&#39;m back | Third blog<\/code><\/pre><\/div>\n\n\n\n<p>3.View Indexes<br>You can view the existing indexes in your table.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; DESCRIBE TABLE posts;\n\nCREATE TABLE myblog.posts (\n    id uuid PRIMARY KEY,\n    author text,\n    content text,\n    title text\n) WITH bloom_filter_fp_chance = 0.01\n    AND caching = {&#39;keys&#39;: &#39;ALL&#39;, &#39;rows_per_partition&#39;: &#39;NONE&#39;}\n    AND comment = &#39;&#39;\n    AND compaction = {&#39;class&#39;: &#39;org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy&#39;, &#39;max_threshold&#39;: &#39;32&#39;, &#39;min_threshold&#39;: &#39;4&#39;}\n    AND compression = {&#39;chunk_length_in_kb&#39;: &#39;64&#39;, &#39;class&#39;: &#39;org.apache.cassandra.io.compress.LZ4Compressor&#39;}\n    AND crc_check_chance = 1.0\n    AND dclocal_read_repair_chance = 0.1\n    AND default_time_to_live = 0\n    AND gc_grace_seconds = 864000\n    AND max_index_interval = 2048\n    AND memtable_flush_period_in_ms = 0\n    AND min_index_interval = 128\n    AND read_repair_chance = 0.0\n    AND speculative_retry = &#39;99PERCENTILE&#39;;\nCREATE INDEX posts_title_idx ON myblog.posts (title);<\/code><\/pre><\/div>\n\n\n\n<p>-&gt; The index name is &#8220;posts_title_idx&#8221;.<\/p>\n\n\n\n<p>4.Drop the Indexes (Optional)<br>If you no longer need the index, drop it.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh:myblog&gt; DROP INDEX posts_title_idx;<\/code><\/pre><\/div>\n\n\n\n<p><strong>Summary<\/strong><\/p>\n\n\n\n<ul>\n<li>Indexing allows for efficient querying of data based on non-primary key columns, improving query performance for specific use cases.<\/li>\n\n\n\n<li>Creating too many indexes can impact write performance and increase storage requirements.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step7_Experiment_with_different_consistency_levels\"><\/span>Step7. Experiment with different consistency levels<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Perform Read operation with CONSISTENCY ALL<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Set with CONSISTENCY ALL\ncqlsh:myblog&gt; CONSISTENCY ALL;\n\n# And then execute queries(The below 3 queries together)\ncqlsh:myblog&gt; SELECT toTimestamp(now()) AS start_time FROM system.local; SELECT * FROM myblog.posts; SELECT toTimestamp(now()) AS end_time FROM system.local;\n\n# and then subtract the start time from the end time to calculate the elapsed time.<\/code><\/pre><\/div>\n\n\n\n<p>2.Perform Read operation with CONSISTENCY ONE<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Set with CONSISTENCY ONE\ncqlsh:myblog&gt; CONSISTENCY ONE;\n\n# And then execute queries(The below 3 queries together)\ncqlsh:myblog&gt; SELECT toTimestamp(now()) AS start_time FROM system.local; SELECT * FROM myblog.posts; SELECT toTimestamp(now()) AS end_time FROM system.local;\n\n# and then subtract the start time from the end time to calculate the elapsed time.<\/code><\/pre><\/div>\n\n\n\n<p>3.Perform Read operation with CONSISTENCY QUORUM<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Set with CONSISTENCY QUORUM\ncqlsh:myblog&gt; CONSISTENCY QUORUM;\n\n# And then execute queries(The below 3 queries together)\ncqlsh:myblog&gt; SELECT toTimestamp(now()) AS start_time FROM system.local; SELECT * FROM myblog.posts; SELECT toTimestamp(now()) AS end_time FROM system.local;\n\n# and then subtract the start time from the end time to calculate the elapsed time.<\/code><\/pre><\/div>\n\n\n\n<p>Consistency levels dictate how many nodes must respond to a read operation before it is considered successful and determine the freshness of the data returned.<\/p>\n\n\n\n<p>4.Perform Write operation with CONSISTENCY ALL<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Set with CONSISTENCY ALL\ncqlsh:myblog&gt; CONSISTENCY ALL;\n\n# And then execute queries(The below 3 queries together)\ncqlsh:myblog&gt; SELECT toTimestamp(now()) AS start_time FROM system.local; INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;ALL&#39;, &#39;ALL&#39;, &#39;Alice&#39;); SELECT toTimestamp(now()) AS end_time FROM system.local;\n\n# and then subtract the start time from the end time to calculate the elapsed time.<\/code><\/pre><\/div>\n\n\n\n<p>5.Perform Write operation with CONSISTENCY ONE<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Set with CONSISTENCY ONE\ncqlsh:myblog&gt; CONSISTENCY ONE;\n\n# And then execute queries(The below 3 queries together)\ncqlsh:myblog&gt; SELECT toTimestamp(now()) AS start_time FROM system.local; INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;ONE&#39;, &#39;ONE&#39;, &#39;Bob&#39;); SELECT toTimestamp(now()) AS end_time FROM system.local;\n\n# and then subtract the start time from the end time to calculate the elapsed time.<\/code><\/pre><\/div>\n\n\n\n<p>6.Perform Write operation with CONSISTENCY QUORUM<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Set with CONSISTENCY QUORUM\ncqlsh:myblog&gt; CONSISTENCY QUORUM;\n\n# And then execute queries(The below 3 queries together)\ncqlsh:myblog&gt; SELECT toTimestamp(now()) AS start_time FROM system.local; INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;QUORUM&#39;, &#39;QUORUM&#39;, &#39;Charlie&#39;); SELECT toTimestamp(now()) AS end_time FROM system.local;\n\n# and then subtract the start time from the end time to calculate the elapsed time.<\/code><\/pre><\/div>\n\n\n\n<p><strong>Summary<\/strong><\/p>\n\n\n\n<ul>\n<li>Consider the trade-offs between consistency, availability, and partition tolerance when choosing a consistency level for your application.<\/li>\n\n\n\n<li>Higher consistency levels provide stronger guarantees but may incur higher latency and lower availability, while lower consistency levels offer better performance but may lead to eventual consistency and potential data conflicts.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step8_Explore_tools_and_techniques_for_monitoring_Cassandra_performance\"><\/span>Step8. Explore tools and techniques for monitoring Cassandra performance<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1Use_nodetool_command_to_see_the_status\"><\/span>1.Use nodetool command to see the status<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Displays_the_status_of_the_nodes_in_the_cluster\"><\/span>Displays the status of the nodes in the cluster.<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool status\n\nDatacenter: se1\n===============\nStatus=Up\/Down\n|\/ State=Normal\/Leaving\/Joining\/Moving\n--  Address     Load       Tokens       Owns (effective)  Host ID                               Rack\nUN  172.18.0.2  364.01 KiB  256          100.0%            2943d0bd-aa7a-476d-ae22-83a3715c1681  rack1\nUN  172.18.0.3  350.93 KiB  256          100.0%            254cb6b1-009b-40bb-a166-579fc33fad67  rack1\nUN  172.18.0.4  371.56 KiB  256          100.0%            d2454910-64ee-4879-a1e9-56289fd6a7fe  rack1<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>Datacenter<\/strong>: Indicates the name of the datacenter to which the nodes belong.<\/li>\n\n\n\n<li><strong>Status<\/strong>: Indicates whether the node is currently up or down.<\/li>\n\n\n\n<li><strong>State<\/strong>: Provides additional information about the state of the node:\n<ul>\n<li><code>UN<\/code>: Up and normal. The node is fully operational and handling requests.<\/li>\n\n\n\n<li><code>\/<\/code>: Separator between the status and state.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Address<\/strong>: IP address or hostname of the node.<\/li>\n\n\n\n<li><strong>Load<\/strong>: The amount of data (in bytes or KiB) that the node is responsible for storing. This includes both the data and the replicas.<\/li>\n\n\n\n<li><strong>Tokens<\/strong>: The number of tokens assigned to the node. Tokens are assigned based on the partitioner and determine the range of data each node is responsible for.<\/li>\n\n\n\n<li><strong>Owns (effective)<\/strong>: Indicates the percentage of the data range that the node owns and is responsible for storing. In a balanced cluster, this value should be close to 100% for each node.<\/li>\n\n\n\n<li><strong>Host ID<\/strong>: Unique identifier for the node.<\/li>\n\n\n\n<li><strong>Rack<\/strong>: The rack within the datacenter where the node is located.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2Use_nodetool_command_to_see_various_metrics\"><\/span>2.Use nodetool command to see various metrics<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Detailed_information_about_the_current_node_in_the_Cassandra_cluster\"><\/span>Detailed information about the current node in the Cassandra cluster.<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool info\nID                     : 2943d0bd-aa7a-476d-ae22-83a3715c1681\nGossip active          : true\nThrift active          : false\nNative Transport active: true\nLoad                   : 315.45 KiB\nGeneration No          : 1706948010\nUptime (seconds)       : 28565\nHeap Memory (MB)       : 374.71 \/ 1864.25\nOff Heap Memory (MB)   : 0.00\nData Center            : se1\nRack                   : rack1\nExceptions             : 0\nKey Cache              : entries 27, size 2.15 KiB, capacity 93 MiB, 313 hits, 350 requests, 0.894 recent hit rate, 14400 save period in seconds\nRow Cache              : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds\nCounter Cache          : entries 0, size 0 bytes, capacity 46 MiB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds\nChunk Cache            : entries 24, size 1.5 MiB, capacity 434 MiB, 99 misses, 1236 requests, 0.920 recent hit rate, NaN microseconds miss latency\nPercent Repaired       : 0.0%\nToken                  : (invoke with -T\/--tokens to see all 256 tokens)<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>ID<\/strong>: Unique identifier for the node.<\/li>\n\n\n\n<li><strong>Gossip active<\/strong>: Indicates whether the gossip protocol, which handles communication between nodes in the cluster, is active on this node (<code>true<\/code> or <code>false<\/code>).<\/li>\n\n\n\n<li><strong>Thrift active<\/strong>: Indicates whether the Thrift protocol, which is used for client communication in older versions of Cassandra, is active on this node (<code>true<\/code> or <code>false<\/code>). In modern versions of Cassandra, Thrift is often disabled by default.<\/li>\n\n\n\n<li><strong>Native Transport active<\/strong>: Indicates whether the native transport protocol, which is used for client communication in newer versions of Cassandra, is active on this node (<code>true<\/code> or <code>false<\/code>).<\/li>\n\n\n\n<li><strong>Load<\/strong>: The amount of data (in bytes or KiB) that the node is responsible for storing.<\/li>\n\n\n\n<li><strong>Generation No<\/strong>: A numeric identifier representing the generation of the node.<\/li>\n\n\n\n<li><strong>Uptime (seconds)<\/strong>: The uptime of the node in seconds.<\/li>\n\n\n\n<li><strong>Heap Memory (MB)<\/strong>: The current and maximum heap memory usage of the node in megabytes.<\/li>\n\n\n\n<li><strong>Off Heap Memory (MB)<\/strong>: The off-heap memory usage of the node in megabytes.<\/li>\n\n\n\n<li><strong>Data Center<\/strong>: The name of the data center where the node is located.<\/li>\n\n\n\n<li><strong>Rack<\/strong>: The rack within the data center where the node is located.<\/li>\n\n\n\n<li><strong>Exceptions<\/strong>: The number of exceptions encountered by the node.<\/li>\n\n\n\n<li><strong>Key Cache<\/strong>: Information about the key cache, including the number of entries, size, hit rate, and save period.<\/li>\n\n\n\n<li><strong>Row Cache<\/strong>: Information about the row cache, including the number of entries, size, hit rate, and save period.<\/li>\n\n\n\n<li><strong>Counter Cache<\/strong>: Information about the counter cache, including the number of entries, size, hit rate, and save period.<\/li>\n\n\n\n<li><strong>Chunk Cache<\/strong>: Information about the chunk cache, including the number of entries, size, hit rate, and miss latency.<\/li>\n\n\n\n<li><strong>Percent Repaired<\/strong>: The percentage of repaired data on the node.<\/li>\n\n\n\n<li><strong>Token<\/strong>: The token assigned to the node, which determines its position in the Cassandra ring.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Information_about_the_thread_pools_and_message_types_processed_by_the_Cassandra_node\"><\/span>Information about the thread pools and message types processed by the Cassandra node<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool tpstats\nPool Name                         Active   Pending      Completed   Blocked  All time blocked\nReadStage                              0         0            478         0                 0\nMiscStage                              0         0              0         0                 0\nCompactionExecutor                     0         0          23064         0                 0\nMutationStage                          0         0            223         0                 0\nMemtableReclaimMemory                  0         0             71         0                 0\nPendingRangeCalculator                 0         0              3         0                 0\nGossipStage                            0         0         144820         0                 0\nSecondaryIndexManagement               0         0              1         0                 0\nHintsDispatcher                        0         0              0         0                 0\nRequestResponseStage                   0         0             35         0                 0\nNative-Transport-Requests              0         0           1721         0                 0\nReadRepairStage                        0         0              1         0                 0\nCounterMutationStage                   0         0              0         0                 0\nMigrationStage                         0         0              4         0                 0\nMemtablePostFlush                      0         0            112         0                 0\nPerDiskMemtableFlushWriter_0           0         0             69         0                 0\nValidationExecutor                     0         0              0         0                 0\nSampler                                0         0              0         0                 0\nMemtableFlushWriter                    0         0             70         0                 0\nInternalResponseStage                  0         0              0         0                 0\nViewMutationStage                      0         0              0         0                 0\nAntiEntropyStage                       0         0              0         0                 0\nCacheCleanupExecutor                   0         0              0         0                 0\n\nMessage type           Dropped\nREAD                         0\nRANGE_SLICE                  0\n_TRACE                       0\nHINT                         0\nMUTATION                     0\nCOUNTER_MUTATION             0\nBATCH_STORE                  0\nBATCH_REMOVE                 0\nREQUEST_RESPONSE             0\nPAGED_RANGE                  0\nREAD_REPAIR                  0<\/code><\/pre><\/div>\n\n\n\n<p><strong>Thread Pool Stats:<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Pool Name<\/strong>: The name of the thread pool.<\/li>\n\n\n\n<li><strong>Active<\/strong>: The number of active threads in the pool.<\/li>\n\n\n\n<li><strong>Pending<\/strong>: The number of pending tasks in the pool (tasks waiting to be executed).<\/li>\n\n\n\n<li><strong>Completed<\/strong>: The number of tasks completed by the pool since the last reset.<\/li>\n\n\n\n<li><strong>Blocked<\/strong>: The number of times a thread was blocked while trying to execute a task in the pool.<\/li>\n\n\n\n<li><strong>All time blocked<\/strong>: The total number of times a thread has been blocked since the pool was created.<\/li>\n<\/ul>\n\n\n\n<p>Each row in the thread pool stats section represents a different thread pool in the Cassandra node. Here are some commonly seen thread pools:<\/p>\n\n\n\n<ul>\n<li><strong>ReadStage<\/strong>: Handles read requests.<\/li>\n\n\n\n<li><strong>CompactionExecutor<\/strong>: Executes compaction tasks (merging and cleaning up SSTables).<\/li>\n\n\n\n<li><strong>MutationStage<\/strong>: Handles mutation (write) requests.<\/li>\n\n\n\n<li><strong>GossipStage<\/strong>: Handles gossip communication between nodes.<\/li>\n\n\n\n<li><strong>RequestResponseStage<\/strong>: Handles request-response communication between clients and nodes.<\/li>\n\n\n\n<li><strong>Native-Transport-Requests<\/strong>: Handles native transport (CQL) requests.<\/li>\n<\/ul>\n\n\n\n<p><strong>Message Type Stats:<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Message type<\/strong>: The type of message processed by the node.<\/li>\n\n\n\n<li><strong>Dropped<\/strong>: The number of messages dropped of that type.<\/li>\n<\/ul>\n\n\n\n<p>Each row in the message type stats section represents a different message type processed by the Cassandra node. Some common message types include reads, mutations, request responses, and hints.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Statistics_about_a_specific_column_family_table_in_a_keyspace\"><\/span>Statistics about a specific column family (table) in a keyspace.<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool cfstats myblog\nTotal number of tables: 37\n----------------\nKeyspace : myblog\n        Read Count: 4\n        Read Latency: 5.25075 ms\n        Write Count: 9\n        Write Latency: 0.3881111111111111 ms\n        Pending Flushes: 0\n                Table: posts\n                SSTable count: 1\n                Space used (live): 5278\n                Space used (total): 5278\n                Space used by snapshots (total): 0\n                Off heap memory used (total): 44\n                SSTable Compression Ratio: 0.9827586206896551\n                Number of partitions (estimate): 6\n                Memtable cell count: 3\n                Memtable data size: 270\n                Memtable off heap memory used: 0\n                Memtable switch count: 2\n                Local read count: 4\n                Local read latency: NaN ms\n                Local write count: 9\n                Local write latency: NaN ms\n                Pending flushes: 0\n                Percent repaired: 0.0\n                Bloom filter false positives: 0\n                Bloom filter false ratio: 0.00000\n                Bloom filter space used: 16\n                Bloom filter off heap memory used: 8\n                Index summary off heap memory used: 28\n                Compression metadata off heap memory used: 8\n                Compacted partition minimum bytes: 30\n                Compacted partition maximum bytes: 86\n                Compacted partition mean bytes: 65\n                Average live cells per slice (last five minutes): NaN\n                Maximum live cells per slice (last five minutes): 0\n                Average tombstones per slice (last five minutes): NaN\n                Maximum tombstones per slice (last five minutes): 0\n                Dropped Mutations: 0<\/code><\/pre><\/div>\n\n\n\n<p><strong>Keyspace Stats:<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Read Count<\/strong>: The total number of read operations performed on the keyspace.<\/li>\n\n\n\n<li><strong>Read Latency<\/strong>: The average latency (in milliseconds) for read operations.<\/li>\n\n\n\n<li><strong>Write Count<\/strong>: The total number of write operations performed on the keyspace.<\/li>\n\n\n\n<li><strong>Write Latency<\/strong>: The average latency (in milliseconds) for write operations.<\/li>\n\n\n\n<li><strong>Pending Flushes<\/strong>: The number of pending flushes for the keyspace.<\/li>\n<\/ul>\n\n\n\n<p><strong>Table Stats:<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Table<\/strong>: The name of the table (<code>posts<\/code> in this case).<\/li>\n\n\n\n<li><strong>SSTable count<\/strong>: The number of SSTables (sorted string tables) for the table.<\/li>\n\n\n\n<li><strong>Space used (live)<\/strong>: The amount of space (in bytes) used by live data.<\/li>\n\n\n\n<li><strong>Space used (total)<\/strong>: The total amount of space (in bytes) used by the table.<\/li>\n\n\n\n<li><strong>Space used by snapshots (total)<\/strong>: The total amount of space (in bytes) used by snapshots of the table.<\/li>\n\n\n\n<li><strong>Off heap memory used (total)<\/strong>: The total amount of off-heap memory used by the table.<\/li>\n\n\n\n<li><strong>SSTable Compression Ratio<\/strong>: The compression ratio of the SSTables.<\/li>\n\n\n\n<li><strong>Number of partitions (estimate)<\/strong>: An estimate of the number of partitions in the table.<\/li>\n\n\n\n<li><strong>Memtable cell count<\/strong>: The number of cells in the memtable.<\/li>\n\n\n\n<li><strong>Memtable data size<\/strong>: The size (in bytes) of data stored in the memtable.<\/li>\n\n\n\n<li><strong>Memtable off heap memory used<\/strong>: The amount of off-heap memory used by the memtable.<\/li>\n\n\n\n<li><strong>Memtable switch count<\/strong>: The number of times the memtable has been switched.<\/li>\n\n\n\n<li><strong>Local read count<\/strong>: The number of read operations performed locally.<\/li>\n\n\n\n<li><strong>Local read latency<\/strong>: The average latency (in milliseconds) for local read operations.<\/li>\n\n\n\n<li><strong>Local write count<\/strong>: The number of write operations performed locally.<\/li>\n\n\n\n<li><strong>Local write latency<\/strong>: The average latency (in milliseconds) for local write operations.<\/li>\n\n\n\n<li><strong>Pending flushes<\/strong>: The number of pending flushes for the table.<\/li>\n\n\n\n<li><strong>Percent repaired<\/strong>: The percentage of repaired data in the table.<\/li>\n\n\n\n<li><strong>Bloom filter false positives<\/strong>: The number of false positives in the Bloom filter.<\/li>\n\n\n\n<li><strong>Bloom filter false ratio<\/strong>: The ratio of false positives in the Bloom filter.<\/li>\n\n\n\n<li><strong>Bloom filter space used<\/strong>: The space (in bytes) used by the Bloom filter.<\/li>\n\n\n\n<li><strong>Bloom filter off heap memory used<\/strong>: The amount of off-heap memory used by the Bloom filter.<\/li>\n\n\n\n<li><strong>Index summary off heap memory used<\/strong>: The amount of off-heap memory used by the index summary.<\/li>\n\n\n\n<li><strong>Compression metadata off heap memory used<\/strong>: The amount of off-heap memory used by compression metadata.<\/li>\n\n\n\n<li><strong>Compacted partition minimum bytes<\/strong>: The minimum size (in bytes) of compacted partitions.<\/li>\n\n\n\n<li><strong>Compacted partition maximum bytes<\/strong>: The maximum size (in bytes) of compacted partitions.<\/li>\n\n\n\n<li><strong>Compacted partition mean bytes<\/strong>: The mean size (in bytes) of compacted partitions.<\/li>\n\n\n\n<li><strong>Average live cells per slice (last five minutes)<\/strong>: The average number of live cells per slice in the last five minutes.<\/li>\n\n\n\n<li><strong>Maximum live cells per slice (last five minutes)<\/strong>: The maximum number of live cells per slice in the last five minutes.<\/li>\n\n\n\n<li><strong>Average tombstones per slice (last five minutes)<\/strong>: The average number of tombstones per slice in the last five minutes.<\/li>\n\n\n\n<li><strong>Maximum tombstones per slice (last five minutes)<\/strong>: The maximum number of tombstones per slice in the last five minutes.<\/li>\n\n\n\n<li><strong>Dropped Mutations<\/strong>: The number of dropped mutations for the table.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Information_about_garbage_collection_GC_statistics_for_the_Cassandra_node\"><\/span>Information about garbage collection (GC) statistics for the Cassandra node<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool gcstats\nInterval (ms) Max GC Elapsed (ms)Total GC Elapsed (ms)Stdev GC Elapsed (ms)   GC Reclaimed (MB)         Collections      Direct Memory Bytes\n     39392432                 327                1264                  86          4367252032                  11                       -1<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>Interval (ms)<\/strong>: The time interval (in milliseconds) covered by the statistics.<\/li>\n\n\n\n<li><strong>Max GC Elapsed (ms)<\/strong>: The maximum elapsed time (in milliseconds) for a single garbage collection cycle during the interval.<\/li>\n\n\n\n<li><strong>Total GC Elapsed (ms)<\/strong>: The total elapsed time (in milliseconds) spent on garbage collection during the interval.<\/li>\n\n\n\n<li><strong>Stdev GC Elapsed (ms)<\/strong>: The standard deviation of the elapsed time (in milliseconds) for garbage collection cycles during the interval.<\/li>\n\n\n\n<li><strong>GC Reclaimed (MB)<\/strong>: The total amount of memory (in megabytes) reclaimed by garbage collection during the interval.<\/li>\n\n\n\n<li><strong>Collections<\/strong>: The total number of garbage collection cycles that occurred during the interval.<\/li>\n\n\n\n<li><strong>Direct Memory Bytes<\/strong>: The amount of direct memory (in bytes) used by the JVM. This value may be <code>-1<\/code> if the information is not available.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Compaction_tasks_that_are_pending_or_in_progress_on_the_Cassandra_node\"><\/span>Compaction tasks that are pending or in progress on the Cassandra node<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool compactionstats\npending tasks: 0<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>Pending Tasks<\/strong>: The number of compaction tasks that are currently pending. A value of <code>0<\/code> indicates that there are no pending compaction tasks.<\/li>\n<\/ul>\n\n\n\n<p>Compaction is the process by which multiple SSTables (sorted string tables) are merged together to optimize storage and improve read performance. It helps to reduce the number of SSTables on disk and improve the efficiency of data retrieval operations.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3Use_nodetool_command_to_monitor_query_performance\"><\/span>3.Use nodetool command to monitor query performance<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Histograms_of_latency_metrics_for_different_types_of_operations_served_by_the_proxy_layer_of_Cassandra\"><\/span>Histograms of latency metrics for different types of operations served by the proxy layer of Cassandra.<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool proxyhistograms\nproxy histograms\nPercentile       Read Latency      Write Latency      Range Latency   CAS Read Latency  CAS Write Latency View Write Latency\n                     (micros)           (micros)           (micros)           (micros)           (micros)           (micros)\n50%                      0.00               0.00               0.00               0.00               0.00               0.00\n75%                      0.00               0.00               0.00               0.00               0.00               0.00\n95%                      0.00               0.00               0.00               0.00               0.00               0.00\n98%                      0.00               0.00               0.00               0.00               0.00               0.00\n99%                      0.00               0.00               0.00               0.00               0.00               0.00\nMin                      0.00               0.00               0.00               0.00               0.00               0.00\nMax                      0.00               0.00               0.00               0.00               0.00               0.00<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>Percentile<\/strong>: The percentile value for which the latency is reported.<\/li>\n\n\n\n<li><strong>Read Latency (micros)<\/strong>: The latency (in microseconds) for read operations.<\/li>\n\n\n\n<li><strong>Write Latency (micros)<\/strong>: The latency (in microseconds) for write operations.<\/li>\n\n\n\n<li><strong>Range Latency (micros)<\/strong>: The latency (in microseconds) for range operations.<\/li>\n\n\n\n<li><strong>CAS Read Latency (micros)<\/strong>: The latency (in microseconds) for Compare-and-Set (CAS) read operations.<\/li>\n\n\n\n<li><strong>CAS Write Latency (micros)<\/strong>: The latency (in microseconds) for Compare-and-Set (CAS) write operations.<\/li>\n\n\n\n<li><strong>View Write Latency (micros)<\/strong>: The latency (in microseconds) for view write operations.<\/li>\n<\/ul>\n\n\n\n<p>For each latency metric, the output provides percentile values ranging from 50% to 99%, as well as minimum (Min) and maximum (Max) values. In the output you provided, all latency values are reported as 0.00 microseconds, indicating that there were no latency measurements recorded during the sampling period.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Histograms_of_various_metrics_related_to_the_specified_table\"><\/span>Histograms of various metrics related to the specified table.<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool tablehistograms myblog.posts\nmyblog\/posts histograms\nPercentile  SSTables     Write Latency      Read Latency    Partition Size        Cell Count\n                              (micros)          (micros)           (bytes)\n50%             0.00              0.00              0.00                72                 3\n75%             0.00              0.00              0.00                86                 3\n95%             0.00              0.00              0.00                86                 3\n98%             0.00              0.00              0.00                86                 3\n99%             0.00              0.00              0.00                86                 3\nMin             0.00              0.00              0.00                30                 0\nMax             0.00              0.00              0.00                86                 3<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>Percentile<\/strong>: The percentile value for which the metrics are reported.<\/li>\n\n\n\n<li><strong>SSTables<\/strong>: The number of SSTables (sorted string tables) involved in the operations.<\/li>\n\n\n\n<li><strong>Write Latency (micros)<\/strong>: The latency (in microseconds) for write operations on the table.<\/li>\n\n\n\n<li><strong>Read Latency (micros)<\/strong>: The latency (in microseconds) for read operations on the table.<\/li>\n\n\n\n<li><strong>Partition Size (bytes)<\/strong>: The size (in bytes) of partitions (rows) in the table.<\/li>\n\n\n\n<li><strong>Cell Count<\/strong>: The number of cells (columns) in the partitions.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Individual_client_sessions_that_have_been_traced\"><\/span>Individual client sessions that have been traced<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 cqlsh -e &quot;SELECT * FROM system_traces.sessions;&quot;\n session_id | client | command | coordinator | coordinator_port | duration | parameters | request | started_at\n------------+--------+---------+-------------+------------------+----------+------------+---------+------------<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><strong>session_id<\/strong>: A unique identifier for the traced session.<\/li>\n\n\n\n<li><strong>client<\/strong>: The IP address or hostname of the client initiating the traced session.<\/li>\n\n\n\n<li><strong>command<\/strong>: The type of command or query executed in the session.<\/li>\n\n\n\n<li><strong>coordinator<\/strong>: The IP address or hostname of the node that acted as the coordinator for the session.<\/li>\n\n\n\n<li><strong>coordinator_port<\/strong>: The port number of the coordinator node.<\/li>\n\n\n\n<li><strong>duration<\/strong>: The duration of the session in milliseconds.<\/li>\n\n\n\n<li><strong>parameters<\/strong>: Additional parameters or settings associated with the session.<\/li>\n\n\n\n<li><strong>request<\/strong>: The text of the query or operation executed in the session.<\/li>\n\n\n\n<li><strong>started_at<\/strong>: The timestamp indicating when the session started.<\/li>\n<\/ul>\n\n\n\n<p>If you&#8217;re not seeing any records in the <code>system_traces.sessions<\/code> table, it means that tracing has not been enabled, or there have been no traced sessions since tracing was enabled. Tracing is typically enabled on a per-session basis using the <code>TRACING ON<\/code> command in <code>cqlsh<\/code> or programmatically through the driver used to interact with Cassandra.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step9_How_to_specify_the_heap_size\"><\/span>Step9. How to specify the heap_size<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/cassandra.apache.org\/doc\/3.11\/cassandra\/configuration\/cass_yaml_file.html\">https:\/\/cassandra.apache.org\/doc\/3.11\/cassandra\/configuration\/cass_yaml_file.html<\/a><\/p>\n\n\n\n<p>1.Locate the &#8216;jvm.options&#8217; file<\/p>\n\n\n\n<p>Navigate to Cassandra installation directory. <br>The <code>jvm.options<\/code> file should be located in this directory.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 bash\n\n# Open the jvm.options file\nroot@xxxxxxxxxxxx:\/# vim \/etc\/cassandra\/jvm.options<\/code><\/pre><\/div>\n\n\n\n<p>2.Edit the &#8216;jvm.options&#8217; file and set the Heap Size parameters<\/p>\n\n\n\n<p>Find the HEAP SETTINGS part in the file and set the value.<br>For example, <code>-Xms<\/code> (initial heap size) and <code>-Xmx<\/code> (maximum heap size).<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># It is recommended to set min (-Xms) and max (-Xmx) heap sizes to\n# the same value to avoid stop-the-world GC pauses during resize, and\n# so that we can lock the heap in memory on startup to prevent any\n# of it from being swapped out.\n-Xms2G\n-Xmx2G<\/code><\/pre><\/div>\n\n\n\n<p>In default these parameters may be not set.<br>In that case, the Heap size is automatically calculated by cassandra.<\/p>\n\n\n\n<p>3.Restart Cassandra<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose restart cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<p>4.Verify the Heap Size with nodetool<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 nodetool info | grep &#39;Heap&#39;\nHeap Memory (MB)       : 321.38 \/ 2000.25\nOff Heap Memory (MB)   : 0.00<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step10_How_to_specify_the_Concurrent_Reads_and_Writes_Parameters\"><\/span>Step10. How to specify the Concurrent Reads and Writes Parameters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Locate the &#8216;cassandra.yaml&#8217; file<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 bash\n\n# Open the cassandra.yaml file\nroot@xxxxxxxxxxxx:\/# vim \/etc\/cassandra\/cassandra.yaml<\/code><\/pre><\/div>\n\n\n\n<p>Navigate to the directory where Cassandra is installed. <br>Typically, the <code>cassandra.yaml<\/code> file is located in the <code>conf<\/code> directory within the Cassandra installation directory.<\/p>\n\n\n\n<p>2.Edit the &#8216;cassandra.yaml&#8217; file and set the Concurrent Reads and Writes Parameters<\/p>\n\n\n\n<ul>\n<li><code>concurrent_reads<\/code>: Specifies the number of simultaneous read operations that Cassandra can perform per data file.<\/li>\n\n\n\n<li><code>concurrent_writes<\/code>: Specifies the number of simultaneous write operations that Cassandra can perform per data file.<\/li>\n<\/ul>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># On the other hand, since writes are almost never IO bound, the ideal\n# number of &quot;concurrent_writes&quot; is dependent on the number of cores in\n# your system; (8 * number_of_cores) is a good rule of thumb.\nconcurrent_reads: 40\nconcurrent_writes: 40<\/code><\/pre><\/div>\n\n\n\n<p>By default, these parameters are set to 32. You can adjust these values based on your workload requirements and hardware resources.<\/p>\n\n\n\n<p>3.Restart Cassandra<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose restart cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step11_How_to_specify_the_Compaction_Strategy\"><\/span>Step11. How to specify the Compaction Strategy<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Understand current Compaction Strategy<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; DESCRIBE TABLE myblog.posts;\n\nCREATE TABLE myblog.posts (\n    id uuid PRIMARY KEY,\n    author text,\n    content text,\n    title text\n) WITH bloom_filter_fp_chance = 0.01\n    AND caching = {&#39;keys&#39;: &#39;ALL&#39;, &#39;rows_per_partition&#39;: &#39;NONE&#39;}\n    AND comment = &#39;&#39;\n    AND compaction = {&#39;class&#39;: &#39;org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy&#39;, &#39;max_threshold&#39;: &#39;32&#39;, &#39;min_threshold&#39;: &#39;4&#39;}\n    AND compression = {&#39;chunk_length_in_kb&#39;: &#39;64&#39;, &#39;class&#39;: &#39;org.apache.cassandra.io.compress.LZ4Compressor&#39;}\n    AND crc_check_chance = 1.0\n    AND dclocal_read_repair_chance = 0.1\n    AND default_time_to_live = 0\n    AND gc_grace_seconds = 864000\n    AND max_index_interval = 2048\n    AND memtable_flush_period_in_ms = 0\n    AND min_index_interval = 128\n    AND read_repair_chance = 0.0\n    AND speculative_retry = &#39;99PERCENTILE&#39;;<\/code><\/pre><\/div>\n\n\n\n<p>-&gt; SizeTieredCompactionStrategy<br>The default value for <code>compaction_strategy<\/code> is typically <code>SizeTieredCompactionStrategy<\/code>.<\/p>\n\n\n\n<p>2.Change the CompactionStrategy<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; ALTER TABLE myblog.posts WITH compaction = {&#39;class&#39;: &#39;LeveledCompactionStrategy&#39;};<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cqlsh&gt; DESCRIBE TABLE myblog.posts;\n\nCREATE TABLE myblog.posts (\n    id uuid PRIMARY KEY,\n    author text,\n    content text,\n    title text\n) WITH bloom_filter_fp_chance = 0.01\n    AND caching = {&#39;keys&#39;: &#39;ALL&#39;, &#39;rows_per_partition&#39;: &#39;NONE&#39;}\n    AND comment = &#39;&#39;\n    AND compaction = {&#39;class&#39;: &#39;org.apache.cassandra.db.compaction.LeveledCompactionStrategy&#39;}\n    AND compression = {&#39;chunk_length_in_kb&#39;: &#39;64&#39;, &#39;class&#39;: &#39;org.apache.cassandra.io.compress.LZ4Compressor&#39;}\n    AND crc_check_chance = 1.0\n    AND dclocal_read_repair_chance = 0.1\n    AND default_time_to_live = 0\n    AND gc_grace_seconds = 864000\n    AND max_index_interval = 2048\n    AND memtable_flush_period_in_ms = 0\n    AND min_index_interval = 128\n    AND read_repair_chance = 0.0\n    AND speculative_retry = &#39;99PERCENTILE&#39;;<\/code><\/pre><\/div>\n\n\n\n<p>Cassandra supports multiple compaction strategies, including:<\/p>\n\n\n\n<ul>\n<li><code>SizeTieredCompactionStrategy<\/code>: Merges SSTables based on their size, with larger SSTables being compacted first.<\/li>\n\n\n\n<li><code>LeveledCompactionStrategy<\/code>: Divides SSTables into levels and compacts SSTables within each level independently.<\/li>\n\n\n\n<li><code>TimeWindowCompactionStrategy<\/code>: Groups SSTables based on their creation time and compacts SSTables within each time window.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step12_How_to_specify_the_Memtable_Configuration\"><\/span>Step12. How to specify the Memtable Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Locate the <strong>&#8216;cassandra.yaml&#8217; file<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 bash\n\n# Open the cassandra.yaml file\nroot@xxxxxxxxxxxx:\/# vim \/etc\/cassandra\/cassandra.yaml<\/code><\/pre><\/div>\n\n\n\n<p>2.Edit the &#8216;cassandra.yaml&#8217; file and set the Memtable Configuration Prameters<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>memtable_flush_writers: 4<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li><code>memtable_flush_writers<\/code>: Specifies the number of threads used for flushing memtables to disk. Increasing this value can improve the performance of write operations by allowing multiple memtables to be flushed concurrently.<\/li>\n<\/ul>\n\n\n\n<p>3.Restart Cassandra<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose restart cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step13_How_to_specify_the_Cache_Configuration\"><\/span>Step13. How to specify the Cache Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Locate the <strong>&#8216;cassandra.yaml&#8217; file<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 bash\n\n# Open the cassandra.yaml file\nroot@xxxxxxxxxxxx:\/# vim \/etc\/cassandra\/cassandra.yaml<\/code><\/pre><\/div>\n\n\n\n<p>2.Edit the &#8216;cassandra.yaml&#8217; file and set the Cache Configuration Parameters<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># Default value is empty to make it &quot;auto&quot; (min(5% of Heap (in MB), 100MB)). Set to 0 to disable key cache.\nkey_cache_size_in_mb: 256\n\n# Default value is 0, to disable row caching.\nrow_cache_size_in_mb: 512\n\n# Default value is empty to make it &quot;auto&quot; (min(2.5% of Heap (in MB), 50MB)). Set to 0 to disable counter cache.\n# NOTE: if you perform counter deletes and rely on low gcgs, you should disable the counter cache.\ncounter_cache_size_in_mb: 128<\/code><\/pre><\/div>\n\n\n\n<p>configuration:<\/p>\n\n\n\n<ul>\n<li><code>key_cache_size_in_mb<\/code>: Specifies the size of the key cache in megabytes. The key cache stores the keys of frequently accessed rows to speed up read operations.<\/li>\n\n\n\n<li><code>row_cache_size_in_mb<\/code>: Specifies the size of the row cache in megabytes. The row cache stores entire rows of frequently accessed tables to speed up read operations.<\/li>\n\n\n\n<li><code>counter_cache_size_in_mb<\/code>: Specifies the size of the counter cache in megabytes. The counter cache stores frequently accessed counter values to speed up read operations for counter columns.<\/li>\n<\/ul>\n\n\n\n<p>3.Restart Cassandra<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose restart cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step14_How_to_specify_the_Native_Transport_Configuration\"><\/span>Step14. How to specify the Native Transport Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Locate the <strong>&#8216;cassandra.yaml&#8217; file<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 bash\n\n# Open the cassandra.yaml file\nroot@xxxxxxxxxxxx:\/# vim \/etc\/cassandra\/cassandra.yaml<\/code><\/pre><\/div>\n\n\n\n<p>2.Edit the &#8216;cassandra.yaml&#8217; file and set the Native Transport Configuration<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># port for the CQL native transport to listen for clients on\n# For security reasons, you should not expose this port to the internet.  Firewall it if needed.\nnative_transport_port: 9042\n\n# The maximum threads for handling requests when the native transport is used.\n# This is similar to rpc_max_threads though the default differs slightly (and\n# there is no native_transport_min_threads, idle threads will always be stopped\n# after 30 seconds).\nnative_transport_max_threads: 16\n\n# The maximum size of allowed frame. Frame (requests) larger than this will\n# be rejected as invalid. The default is 256MB. If you&#39;re changing this parameter,\n# you may want to adjust max_value_size_in_mb accordingly. This should be positive and less than 2048.\nnative_transport_max_frame_size_in_mb: 256<\/code><\/pre><\/div>\n\n\n\n<p>transport:<\/p>\n\n\n\n<ul>\n<li><code>native_transport_port<\/code>: Specifies the port number on which the native transport listens for client connections. Clients connect to this port to communicate with the Cassandra cluster using the native protocol.<\/li>\n\n\n\n<li><code>native_transport_max_threads<\/code>: Specifies the maximum number of threads allowed for handling native transport requests concurrently. Increasing this value can improve the throughput of client requests.<\/li>\n\n\n\n<li><code>native_transport_max_frame_size_in_mb<\/code>: Specifies the maximum frame size allowed for incoming messages over the native transport. Messages larger than this size will be rejected.<\/li>\n<\/ul>\n\n\n\n<p>3.Restart Cassandra<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose restart cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step15_Learn_about_authentication_and_authorization\"><\/span>Step15. Learn about authentication and authorization<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1.Edit the <code>cassandra.yaml<\/code> configuration file to enable authentication and authorization<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 bash\n\n# Open the cassandra.yaml file\nroot@xxxxxxxxxxxx:\/# vim \/etc\/cassandra\/cassandra.yaml\n\nauthenticator: PasswordAuthenticator\nauthorizer: CassandraAuthorizer<\/code><\/pre><\/div>\n\n\n\n<p>This configuration sets the <code>PasswordAuthenticator<\/code> as the authentication mechanism.<\/p>\n\n\n\n<p><code>CassandraAuthorizer<\/code> as the authorizer.<\/p>\n\n\n\n<p>2.Restart the Cassandra container<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose restart cassandra-node1<\/code><\/pre><\/div>\n\n\n\n<p>3.Create a Superuser<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 cqlsh -u cassandra -p cassandra<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cassandra@cqlsh&gt; CREATE ROLE admin WITH SUPERUSER = true AND LOGIN = true AND PASSWORD = &#39;password&#39;;<\/code><\/pre><\/div>\n\n\n\n<p>4.Create a Regular User and Assign Permissions<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>cassandra@cqlsh&gt; CREATE ROLE user1 WITH LOGIN = true AND PASSWORD = &#39;password&#39;;\ncassandra@cqlsh&gt; GRANT SELECT ON KEYSPACE myblog TO user1;\ncassandra@cqlsh&gt; exit<\/code><\/pre><\/div>\n\n\n\n<p>5.Try to use a Regular User (Can SELECT query, but can not INSERT query)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker exec -it cassandra-node1 cqlsh -u user1 -p password\nuser1@cqlsh&gt; USE myblog;\nuser1@cqlsh:myblog&gt; INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;User blog&#39;, &#39;Hello&#39;, &#39;User&#39;);\nuser1@cqlsh:myblog&gt; SELECT * FROM posts;\n\n id                                   | author  | content     | title\n--------------------------------------+---------+-------------+-------------\n 6502fc83-c78d-49d9-8928-79a83cc6eb70 |    John |    I&#39;m back |  Third blog\n 81e302a7-cca0-4745-b002-14b9d6453acb | Charlie |      QUORUM |      QUORUM\n 94b50ea4-f07b-4679-b04e-2e6a982187cb |     Bob |         ONE |         ONE\n 1f13251d-7dd8-4d3d-8ce4-ccd667e7f458 |   Alice |         ALL |         ALL\n 6f2a5531-85a8-4317-8459-2c3e94e38bc5 |    Mila | Good night. | Second blog\n\n(5 rows)\n\nuser1@cqlsh:myblog&gt; INSERT INTO posts (id, title, content, author) VALUES (uuid(), &#39;User blog&#39;, &#39;Hello&#39;, &#39;User&#39;);\nUnauthorized: Error from server: code=2100 [Unauthorized] message=&quot;User user1 has no MODIFY permission on &lt;table myblog.posts&gt; or any of its parents&quot;<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The target Cassandra version i&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages\/812"}],"collection":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/comments?post=812"}],"version-history":[{"count":51,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages\/812\/revisions"}],"predecessor-version":[{"id":1069,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages\/812\/revisions\/1069"}],"wp:attachment":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/media?parent=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}