注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 雨天愁浪 于 2021-5-10 15:58 编辑
. ----
做Data engineer 4年了,在小公司大公司各呆过两年。最近在准备跳槽,总结了一些big data方面的知识点,主要集中在spark和streaming processing。
~~~求大米看面经~~
Resilient Distributed Datasets (RDD): They abstract a distributed dataset in the cluster, usually executed in the primary memory. .--
Operations: They represent transformations or actions that are made within a RDD. A Spark program is normally defined like a sequence of transformations or actions that are performed in a dataset.. .и
Spark Context: Context is the object that connects Spark to the program being developed. It can be accessed as a variable in a program that uses its resources.. Waral dи,
Cluster - 1 driver + N executors. Collections of JVM running Spark
Driver: main JVM that orchestrate processing data within executors. Executors: worker JVM running jobs
Cost to consider: EC2, S3, EMR
Spark History Server jobs/stages tab can find task time breakdown and identify task skew and data skew, can also find task level log.
.--
how to calculate memory and other usual spark parameters?
1 node has multiple cores. Spark tasks runs by executors. Executor is within one node. You can specify 1 executor has how many cores (usually 5 for good HDFS throughput). Usually on each node, leave 1 core for Hadoop/Yarn daemons, and left cores can be assigned to executors. Across all nodes, leave 1 executor for driver/application manager (Driver memory and driver cores can be specified differently, but recommend to use the same as executors). Node Memory is fixed, and split evenly to executors. Executor.memoryOverhead is max(384mb, 10% of executor memory). round down every where except calculate memoryOverhead. default.parallelism=sql.shuffle.partitions= total num of executor cores *2. sql.shuffle.partitions is only for dataframe.
Always set the virtual and physical memory check flag to false. "yarn.nodemanager.vmem-check-enabled":"false", "yarn.nodemanager.pmem-check-enabled":"false"
e.g. 10 nodes, 16 cores/node. 64gb memory/node. Then executor.cores=5. leave 1 core per node for Hadoop/Yarn daemons, then num cores available per node=15. then number of executors per nodes=30/10=3. executor.instances=3*10-1=29. total memory per executor=64gb/3=21gb. Executor.memoryOverhead=7%*21=3gb. So actual executor.memory=21-3=18gb. driver.memory=executor.memory=18gb. Driver.cores=executor.cores=5. default.parallelism=sql.shuffle.partitions= executor.instances * spark.executors.cores * 2=29*5*2=290
Spark join strategy https://towardsdatascience.com/s ... k-join-c0e7b4572bcf . 1point3acres.com
Broadcast Hash Join: first creating a Hash Table based on join_key of smaller relation and then looping over larger relation to match the hashed join_key values. Also, this is only supported for ‘=’ join. Not support for full outer join.. .и
Shuffle Hash join: Shuffle Hash Join involves moving data with the same value of join key in the same executor node followed by Hash Join, as we know data of the same key will be present in the same executor. Pick if one side is small enough to build the local hash map, and is much smaller than the other side. only supported for ‘=’ join. Not support for full outer join.
Sort-merge Join: Shuffle sort-merge join involves, shuffling of data to get the same join_key with the same worker, and then performing sort-merge join operation at the partition level in the worker nodes. Require join keys are sortable. only supported for ‘=’ join.. 1point3acres
Cartesian Join: the cartesian product(similar to SQL) of the two relations is calculated to evaluate join. Only for inner join.
Broadcast nested loop join: very slow. Χ
for record_1 in relation_1:
for record_2 in relation_2:
# join condition is executed
Operations requiring shuffle (exchange in spark plan): join, groupByKey, reduceByKey, partition by, etc.
Whenever a shuffle will happen, a new stage start. The data is written in disk in previous step, so the shuffle can read from any node; and can retry in case of failure in shuffle. Shuffle is slow because of Disk I/O, Involves data serialization and deserialization, Network I/O. try to reduce shuffle. And tune spark.sql.shuffle.partitions. 1point3acres
How to deal with data skew? https://developer.aliyun.com/article/741111
If data is skewed from input source, repartition or rewrite it.
Change join key or partition key to make data evenly distributed
Increase parallelism to avoid a task has too many data
Larger cluster
Reduce number of sortMergeJoins. check 1point3acres for more.
Try broadcast if one of the table <2Gb. Use broadcast hints
Data preprocess to remove unnecessary data. If a lot of null values in join key. Separate into 2 dataset, 1 non-null, 1 null, then union them.
specify the hint ` /*+ SKEW ('<table_name>') */ ` for a join that describes the column and the values upon which skew is expected. Based on that information, the engine automatically ensures that the skewed values are handled appropriately.
Key salting. 一大一小表可以大表加盐小表explode. 2个大表可以都随机加盐,然后按原值做cardisian join. From 1point 3acres bbs
How to tune spark performance?
More batch reading rather than individual record update, more analysis than processing focused. Data in read efficient format like Parquet, data in a flattened schema to use S3Select (for CSV and JSON, but not work with nested json)
Avoid too many small files
filter out data as early as possible in your application pipeline
Use dataframe/dataset over RDD, because they includes several optimization modules to improve the performance.
Data object should be ready to join with other dataset, no need to derive data based on service implementation logic.
Avoid UDF, use built-in functions
Replace union with flattenmap, or cache before union. Because each df in union runs independently before shuffle. Self-union will dup comuptation.
Cache
Repartition
Coalesce - merge files together, reduce number of partitions/files, faster than repartition since less shuffle. Coalesce to number of cores.
Parallelize - number of parallization = number of cores-baidu 1point3acres
Reduce distinct unions
Bucketing. if a large tables are used in join multiple times, write to s3 by join key. Define how many number of buckets and bucketBy key (join key).. 1point 3acres
Aggregate before shuffle.
set up a garbage collector when handling large volume of data through Spark.
Tune spark.driver.memory, executor-memory, num-executors, and executor-cores, and spark.sql.shuffle.partitions, yarn.scheduler.maximum-allocation-mb ..
https://aws.amazon.com/cn/blogs/ ... ions-on-amazon-emr/
How to choose AWS EMR node type?
For memory-intensive applications, prefer R type instances. For compute-intensive applications, prefer C type instances. For applications balanced between memory and compute, prefer M type general-purpose instances.
you can run spark-submit with the –verbose option. Also, you can use Ganglia and Spark UI to monitor the application progress, Cluster RAM usage, Network I/O, etc.. check 1point3acres for more.
Streaming processing
一个很comprehensive的总结 https://medium.com/@chandanbaran ... essing-91ea3f04675b
What is unbounded data and bounded data? ..
Unlike Batch processing where data is bounded with a start and an end in a job and the job finishes after processing that finite data, Streaming is meant for processing unbounded data coming in realtime continuously for days,months,years and forever.
What need to be considered for streaming processing?
Delivery Guarantees. Atleast-once, Atmost-once, Exactly-once (most desirable but hard)
Fault Tolerance. Distributed replica, checkpointing the state of streaming to some persistent storage from time to time
State Management : stateful processing requires maintain some state (e.g. counts of each distinct word seen in records), framework should be able to provide some mechanism to preserve and update state information.
Preformance
Advanced Features : Event Time Processing, Watermarks, Windowing
Maturity: proven by big company. Great community support. Compatible with company exiting tools. What is learning curve
Whether need Lambda architecture
How to compare Spark streaming and Flink, 2 most popular engine?
Both in-memory processing. Both fast. Both support lambda architecture, but Flink batch didn’t proven by big company. Spark use micro-batch processing, Flink use streaming processing. Flink has less parameters to tune. Spark is stateless and lacks many advanced features as Flink. Spark has better community support, larger user base.
How to compare native stream processing with micro-batch processing?
Native Streaming: every record is processed as soon as it arrives. the minimum latency. But it is hard to achieve fault tolerance without compromising on throughput as for each record, we need to track and checkpoint once processed. Also, state management is easy as there are long running processes which can maintain the required state easily.
Micro-batching: Fault tolerance is good as it is essentially a batch and throughput is also high as processing and checkpointing will be done in one shot for group of records. But it has latency. Also efficient state management will be a challenge to maintain.
Kafka
Kafaka is a distributed, event streaming, message publishing/subscribing platform. It is like a storage as broker between data publisher and consumer.
Streaming is different than Message Queue. MQ is point-to-point, where consumer can define which message to consume individually. Streaming is publish/subscribe all event in a topic.Property of Kafka: Keep Stream history, Scalable Consumption, Immutable data, Scalable, highly available
Benefits of Kafka: 1. loose decoupling to support micro-services. Small container. 2. fully distributed. 3. event-based. 4. 0 downtime 5. easy to scale. 6. no vendor lock in.. check 1point3acres for more.
To send a event: 1. choose a topic, 2. whether to use a key, 3. choose acknowledge level (0-fire and forget, 1-wait for 1 broker, ALL-wait for all broker), 4. whether retry. No retry risk losing message. Retry risk dup messages.
. ΧTo receive a event: 1. choose a topic, 2. where to start, 3. how to manage commit offsets (automatic, manual asynchronous, manual synchronous), 4. choose consumer group
Message就是row, topic就是table. Kafka has multiple brokers(nodes). 1 topic are distributed by partition in multiple brokers. Each topic in one partition is sorted by the key you defined. Across partitions/brokers you have to mergesort provided by Kafka function.
Replica of partitions. One is leader, other are followers. Always connect to lead only. When lead is down, Kafka choose one of Followers as leader and update metadata.
Kafka Connect allows you to continuously ingest data from external systems into Kafka, and vice versa.
. 1point 3acres
~~~求大米看面经~~
.
|