в чем разница между «старым поколением» и «старым пространством» в `jstat -gccapacity`? [duplicate]

Python

Невозможно изменить одно вложенное поле. Вы должны воссоздать целую структуру. В этом конкретном случае самым простым решением является использование cast.

Сначала куча импорта:

from collections import namedtuple
from pyspark.sql.functions import col
from pyspark.sql.types import (
    ArrayType, LongType, StringType, StructField, StructType)

и данные примера:

Record = namedtuple("Record", ["a", "b", "c"])

df = sc.parallelize([([Record("foo", 1, 3)], )]).toDF(["array_field"])

Давайте подтвердим, что схема такая же, как в вашем случае:

df.printSchema()
root
 |-- array_field: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- a: string (nullable = true)
 |    |    |-- b: long (nullable = true)
 |    |    |-- c: long (nullable = true)

Вы можете определить новую схему, например, как строку:

str_schema = "array>"

df.select(col("array_field").cast(str_schema)).printSchema()
root
 |-- array_field: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- a_renamed: string (nullable = true)
 |    |    |-- b: long (nullable = true)
 |    |    |-- c: long (nullable = true)

или DataType:

struct_schema = ArrayType(StructType([
    StructField("a_renamed", StringType()),
    StructField("b", LongType()),
    StructField("c", LongType())
]))

 df.select(col("array_field").cast(struct_schema)).printSchema()
root
 |-- array_field: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- a_renamed: string (nullable = true)
 |    |    |-- b: long (nullable = true)
 |    |    |-- c: long (nullable = true)

Scala

Те же методы могут использоваться в Scala:

case class Record(a: String, b: Long, c: Long)

val df = Seq(Tuple1(Seq(Record("foo", 1, 3)))).toDF("array_field")

val strSchema = "array>"

df.select($"array_field".cast(strSchema))

или

import org.apache.spark.sql.types._

val structSchema = ArrayType(StructType(Seq(
    StructField("a_renamed", StringType),
    StructField("b", LongType),
    StructField("c", LongType)
)))

df.select($"array_field".cast(structSchema))

Возможные улучшения:

Если вы используете экспрессивную обработку данных или библиотеку обработки JSON, было бы проще сбросить типы данных в строку dict или JSON и взять ее оттуда например (Python / toolz ):

from toolz.curried import pipe, assoc_in, update_in, map
from operator import attrgetter

# Update name to "a_updated" if name is "a"
rename_field = update_in(
    keys=["name"], func=lambda x: "a_updated" if x == "a" else x)

updated_schema = pipe(
   #  Get schema of the field as a dict
   df.schema["array_field"].jsonValue(),
   # Update fields with rename
   update_in(
       keys=["type", "elementType", "fields"],
       func=lambda x: pipe(x, map(rename_field), list)),
   # Load schema from dict
   StructField.fromJson,
   # Get data type
   attrgetter("dataType"))

df.select(col("array_field").cast(updated_schema)).printSchema()

9
задан Steve Kehlet 6 July 2012 в 01:39
поделиться

1 ответ

Я просто ищу из источника jdk

вкратце: OGC = sum(all OC)

Ген может содержать БОЛЕЕ ЧЕМ ОДНО пространства.

Однако, Hotspot old gen имеет только 1 пробел (у молодого поколения есть 3: eden, s0 и s1), jstat показывает для них то же самое значение.

ЧТО ТАКОЕ OC и OGC

из jdk/src/share/classes/sun/tools/jstat/resources/jstat_options

Я получил

OGC = sun.gc.generation.1.capacity

OC = sun.gc.generation.1.space.0.capacity

  column {
    header "^OGC^"  /* Old Generation Capacity - Current */
    data sun.gc.generation.1.capacity
    scale K
    align right
    width 11
    format "0.0"
  }
  column {
    header "^OC^"   /* Old Space Capacity - Current */
    data sun.gc.generation.1.space.0.capacity
    scale K
    align right
    width 11
    format "0.0"
  }

КАК МНОГИЕ ПРОСТРАНСТВА В GEN.1

выполнить groovy-код ниже, чтобы изучить

import java.lang.management.ManagementFactory
import sun.jvmstat.monitor.*;

name = ManagementFactory.runtimeMXBean.name
pid  = name[0..<name.indexOf('@')]
vmId = new VmIdentifier(pid)
vm   = MonitoredHost.getMonitoredHost(vmId).getMonitoredVm(vmId, 0)

println 'Y count :' + vm.findByName('sun.gc.generation.0.spaces').longValue()
println 'O count :' + vm.findByName('sun.gc.generation.1.spaces').longValue()
Выход

:

Y count :3
O count :1

Вы можете сделать то же самое для GEN.2 (PERM GEN)

8
ответ дан farmer1992 23 August 2018 в 02:44
поделиться
  • 1
    Это отличный ответ, но вы можете удалить ненужную ненормативную лексику? – Steve Kehlet 2 November 2013 в 22:27
  • 2
    @SteveKehlet извините – farmer1992 3 November 2013 в 00:34
Другие вопросы по тегам:

Похожие вопросы: