diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install
index f47151f..73b4d67 100644
--- a/core/modules/comment/comment.install
+++ b/core/modules/comment/comment.install
@@ -382,6 +382,15 @@ function comment_update_8003(&$sandbox) {
 }
 
 /**
+ * Convert variables to state.
+ */
+function comment_update_8004() {
+  update_variables_to_state(array(
+    'node_cron_comments_scale' => 'comment.count_scale',
+  ));
+}
+
+/**
  * @} End of "addtogroup updates-7.x-to-8.x".
  * The next series of updates should start at 9000.
  */
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 7b6eda4..5e999ea 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1318,7 +1318,7 @@ function comment_node_update_index(Node $node, $langcode) {
  */
 function comment_update_index() {
   // Store the maximum possible comments per thread (used for ranking by reply count)
-  variable_set('node_cron_comments_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchField()));
+  state()->set('comment.count_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchField()));
 }
 
 /**
@@ -2004,7 +2004,7 @@ function comment_ranking() {
       ),
       // Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
       'score' => '2.0 - 2.0 / (1.0 + node_comment_statistics.comment_count * CAST(:scale AS DECIMAL))',
-      'arguments' => array(':scale' => variable_get('node_cron_comments_scale', 0)),
+      'arguments' => array(':scale' => state()->get('comment.count_scale') ?: 0),
     ),
   );
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php
index fbd754f..a116745 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php
@@ -47,6 +47,10 @@ public function testSystemVariableUpgrade() {
       'value' => 1304208000,
       'variable_name' => 'update_last_email_notification',
     );
+    $expected_state['comment.count_scale'] = array(
+      'value' => 1.0 / 1000,
+      'variable_name' => 'node_cron_comments_scale',
+    );
 
     foreach ($expected_state as $name => $data) {
       $this->assertIdentical(state()->get($name), $data['value']);
diff --git a/core/modules/system/tests/upgrade/drupal-7.state.system.database.php b/core/modules/system/tests/upgrade/drupal-7.state.system.database.php
index 47c86f2..b58857e 100644
--- a/core/modules/system/tests/upgrade/drupal-7.state.system.database.php
+++ b/core/modules/system/tests/upgrade/drupal-7.state.system.database.php
@@ -23,3 +23,7 @@
   ->key(array('name' => 'node_access_needs_rebuild'))
   ->fields(array('value' => serialize(TRUE)))
   ->execute();
+db_merge('variable')
+  ->key(array('name' => 'node_cron_comments_scale'))
+  ->fields(array('value' => serialize(1.0 / 1000)))
+  ->execute();
