avatarMark Ellis

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5243

Abstract

name">C</span>:\Users\feng\Kafka\kraft>ls docker-compose.yml <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>docker-compose up -d [+] Running <span class="hljs-number">2</span>/<span class="hljs-number">2</span>

  • Network kraft_default Created <span class="hljs-number">0.0</span>s
  • Container kraft-kafka<span class="hljs-number">-1</span> Started

<span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES <span class="hljs-number">54342e49</span>a1f2 bitnami/<span class="hljs-name">kafka</span>:latest <span class="hljs-string">"/opt/bitnami/script…"</span> <span class="hljs-number">18</span> seconds ago Up <span class="hljs-number">17</span> seconds <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">9092</span>-><span class="hljs-number">9092</span>/tcp kraft-kafka<span class="hljs-number">-1</span> <span class="hljs-number">0.5</span>s</pre></div><h2 id="095a">1.5 Create Kafka topic</h2><p id="0672">We’ll login to the instance and create a test topic in Kafka</p><div id="aaf2"><pre><span class="hljs-comment">## Login to Kafka docker instance</span> C:\Users\feng\Kafka\kraft>docker exec -it kraft-kafka-1 <span class="hljs-string">/bin/bash</span> <span class="hljs-keyword">cd</span> <span class="hljs-string">/opt/bitnami/kafka</span> <span class="hljs-string">/opt/bitnami/kafka</span> <span class="hljs-string">./bin/kafka-topics.sh</span> <span class="hljs-params">--version</span> 3.4.0 <span class="hljs-params">(Commit:2e1947d240607d53)</span>

<span class="hljs-comment">## Create topic named "test_topic"</span> <span class="hljs-string">/opt/bitnami/kafka</span>$ <span class="hljs-string">./bin/kafka-topics.sh</span> <span class="hljs-params">--bootstrap-server</span> localhost<span class="hljs-function">:9092</span> <span class="hljs-params">--create</span> <span class="hljs-params">--replication-factor</span> 1 <span class="hljs-params">--partitions</span> 2 <span class="hljs-params">--topic</span> test_topic WARNING: Due to limitations in metric names, topics with a period <span class="hljs-params">('.')</span> or underscore <span class="hljs-params">('_')</span> could collide. To avoid issues it is best to use either, but not both. Created topic test_topic.

<span class="hljs-comment">## List current topics</span> <span class="hljs-string">/opt/bitnami/kafka</span>$ <span class="hljs-string">./bin/kafka-topics.sh</span> <span class="hljs-params">--bootstrap-server</span> localhost<span class="hljs-function">:9092</span> <span class="hljs-params">--list</span> test_topic</pre></div><p id="8304">So by now we have a Kafka docker instance running successfully.</p><h1 id="80ee">2 Run sanity checks using simple producer/consumer app codes</h1><h2 id="b504">2.1 Setup producer/consumer Dev ENV</h2><div id="8e5b"><pre>## Create conda env <span class="hljs-keyword">for</span> Kafka producer <span class="hljs-keyword">and</span> cosumer <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>conda create -n kafka_env python=<span class="hljs-number">3.10</span> ... <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>conda activate kafka_env

Install kafka-python <span class="hljs-built_in">package</span>

(kafka_env) <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>pip install kafka-python ... (kafka_env) <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>pip list | grep kafka kafka-python <span class="hljs-number">2.0</span><span class="hljs-number">.2</span>

Install Faker <span class="hljs-built_in">package</span> to generate dummy messages

(kafka_env) <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>pip install Faker ... (kafka_env) <span class="hljs-name">C</span>:\Users<span class="hljs-number">6119811</span>\Kafka\kraft>pip list | grep Faker Faker <span class="hljs-number">17.3</span><span class="hljs-number">.0</span></pre></div><h2 id="6701">2.2 Code examples</h2><p id="c7dc">Now we can use VSCode to create producer/consumer files.</p><p id="fc6a">Producer generate fake user info as JSON load sending to Kafka topic “test_topic”. producer.py is like following.</p><div id="8801"><pre><span class="hljs-keyword">import</span> time <span class="hljs-keyword">import</span> json <span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime <span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaProducer <span class="hljs-keyword">from</span> faker <span class="hljs-keyword">import</span> Faker

<span class="hljs-comment"># JSON messages needs to be serialized</span> <span class="hljs-comment"># when sending to Kafka topic </span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">json_serializer</span>(<span class="hljs-params">message</span>): <span class="hljs-keyword">return</span> json.dumps(message

Options

).encode(<span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Kafka Producer</span> producer = KafkaProducer( bootstrap_servers=[<span class="hljs-string">'localhost:9092'</span>], value_serializer=json_serializer ) <span class="hljs-keyword">if</span> name == <span class="hljs-string">'main'</span>: fake = Faker() <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-number">3</span>): <span class="hljs-comment"># Generate a fake JSON message</span> name = fake.name() email = fake.email() city = fake.city() fake_message = { <span class="hljs-string">"name"</span>: name, <span class="hljs-string">"email"</span>: email, <span class="hljs-string">"city"</span>: city }

    <span class="hljs-comment"># Send fake JSON message to Kafka topic</span>
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f'<span class="hljs-subst">{datetime.now()}</span>: Message = <span class="hljs-subst">{<span class="hljs-built_in">str</span>(fake_message)}</span>'</span>)
    producer.send(<span class="hljs-string">'test_topic'</span>, fake_message)
                                                          
    time.sleep(<span class="hljs-number">1</span>)</pre></div><p id="6594">And here is our consumer.py</p><div id="a19b"><pre><span class="hljs-keyword">import</span> json 

<span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaConsumer

<span class="hljs-keyword">if</span> name == <span class="hljs-string">'main'</span>: <span class="hljs-comment"># Kafka Consumer</span> consumer = KafkaConsumer( <span class="hljs-string">'test_topic'</span>, bootstrap_servers=<span class="hljs-string">'localhost:9092'</span>, auto_offset_reset=<span class="hljs-string">'earliest'</span> ) <span class="hljs-keyword">for</span> message <span class="hljs-keyword">in</span> consumer: <span class="hljs-built_in">print</span>(json.loads(message.value))</pre></div><p id="8d09">OK, now let’s start consumer and run producer to send some fake message for a sanity check.</p><div id="572f"><pre><span class="hljs-comment"># Run producer</span> (kafka_env) C:\Users\feng\Kafka\kraft>python producer.py 2023-02-25 18:48:41.143953: Message = {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Susan Best'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Kellytown'</span>} 2023-02-25 18:48:42.160545: Message = {<span class="hljs-string">'name'</span>: <span class="hljs-string">'James Wilson'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Lake Bryanfort'</span>} 2023-02-25 18:48:43.177933: Message = {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Haley Brooks'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'East Janetburgh'</span>}

<span class="hljs-comment"># Monitor consumer</span> (kafka_env) C:\Users\feng\Kafka\kraft>python consumer.py {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Susan Best'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Kellytown'</span>} {<span class="hljs-string">'name'</span>: <span class="hljs-string">'James Wilson'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Lake Bryanfort'</span>} {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Haley Brooks'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'East Janetburgh'</span>}</pre></div><p id="3143">Great, our Kafka Docker instance and simple applications are working as expected!</p><p id="79d6">Happy Reading!</p><div id="2213" class="link-block"> <a href="https://medium.com/@fengliplatform/membership"> <div> <div> <h2>Join Medium with my referral link - Feng Li</h2> <div><h3>Writing helps ourselves, sharing helps many. It started from study notes for myself with no pressure of perfection…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*K9psL5RefQfuKkzr)"></div> </div> </div> </a> </div></article></body>

How I Finally Triggered the M1 Mac Fan

Is there an issue with the 24" M1 iMac’s single fan?

Image courtesy of author

The 16" MacBook Pro used to be my daily driver. It was also the noisiest computer I’ve ever owned.

Any kind of remotely intensive task would spin up the fans immediately. As soon as the outside temperature crept above 20 degrees Celsius, the same thing would happen.

It’s one of the reasons it had to go.

But the main reason that wonderful laptop spent such a relatively short time in my life was the launch of the M1 chip. It has transformed computing for me. Fast, power-efficient and capable of being the supercar you can drive to the supermarket, it makes for an incredibly exciting future.

It has also powered some of the quietest computers I’ve ever owned. And this is because, try as I might, I’ve not been able to kick the M1 fan into life.

That is, until last week, when it finally made its presence known under the most unsuspecting of circumstances.

A timely reminder that computer fans exist

It’s hot in the UK at the moment (for us, that means anything above 25 degrees Celsius; the trigger temperature for a perceivable increase in the amount of weather talk). As noted a moment ago, if I was still using the 16" MacBook Pro, it would be sweating as heavily as I was yesterday in the garden and expelling as much hot air as a portable air-conditioning unit.

Since its departure, I’d forgotten what it sounded like when a computer’s fan comes on. This explains why I was so perplexed by the noise in my conservatory the other day.

For anyone who doesn’t have a conservatory (ours came with the house), let me explain what they’re like in the summer.

They are completely unusable.

You can barely enter ours when the mercury rises. Opening the doors to it literally feels like opening the door to an oven that has reached its 200C baking temperature.

Since I rejigged my studio to accommodate the new 24" M1 iMac, I’ve relegated the Intel-based 27" iMac to the conservatory. It’ll soon become my macOS Monterey test machine but will lay dormant until the public beta arrives.

Shame I forgot to turn it off, then.

You see, when I entered the conservatory this weekend, I wasn’t only hit with a blast of hot air like the one you experience when stepping off a plane in a hot country — there was also a sound I immediately recognised but couldn’t place. Was a neighbour jet-washing their patio? Perhaps someone had decided to do a bit of furniture upscaling with a hand sander. Or was it simply that the wind was carrying the sound from Coventry Airport more clearly than usual?

Nope, it was the 27" iMac’s fan spinning at full tilt in a fruitless bid to keep the CPU within a manageable temperature range.

Poor thing. But it wasn’t the only computer fan I’d heard that week.

The most unlikely culprit

After wrapping up the latest episode of Eight or Sixteen, I ended the Zoom chat and waited for the video conversion to take place.

I decided to crack on with my work while the video of Rob and I talking wearily about the emergence of widgets in iPadOS 15 created itself.

However, while I tapped away on my keyboard, I became aware of a noise I hadn’t heard in the studio for quite some time. As usual (and just as I would a couple of days later), I assumed it was a neighbour undertaking some form of DIY, or the distant sound of an aircraft.

But it wasn’t. It was the 24" M1 iMac in front of me. Somehow, I’d triggered the M1’s fan for the first time ever.

There was only one possible reason for this, which was the aforementioned Zoom video export. Nothing else even remotely taxing was running on the machine at the time but, sure enough, Zoom’s decoding (or whatever it does during that process) was clearly intensive enough to trigger some concern about the temperature of the M1 chip inside the iMac’s chin.

Equally, it confirmed that the base level 24" M1 iMac indeed has just one fan, versus the two in the next model up. The noise (it was pretty loud) and breeze could only be heard and felt from the left-hand vent.

Well, what do you know; finally, I’d managed to kick the M1 fan into action without even trying.

Should we be worried about the 24" iMac’s single fan?

It’s important to reiterate that I have the base level 24" iMac — the cheapest one you can buy. That means it has 8GB of RAM, the 7-core GPU and, yes, just the one CPU fan.

I don’t, therefore, expect it to be a content production powerhouse for my business. Indeed, I’ve decided to use it purely for ‘normal’ work, leaving the job of video editing to the brilliant M1 Mac mini that now occupies the permanently standing desk you can see behind me on my YouTube videos.

I’m also yet to perform any kind of video editing stress test on it. Although, clearly, I inadvertently did exactly that with the Zoom export. I have absolutely no idea what Zoom does when it exports video and audio at the end of a recorded call (if you do, please let me know in the comments), but it’s obviously pretty intensive.

My user experience of M1 Macs up until this point has been one of blissful silence. I’ve heard stories of people somehow managing to kick in the fan on their own M1 machines, but this is the first time I’ve experienced it. And yes, it was a surprise.

Reports about degraded performance due to thermal throttling on this base level 24" iMac are starting to emerge. According to Max Tech, there are “HUGE” differences between the cheapest variant and the one featuring the 8-core GPU. His tests revealed that the beefed-up variant performed around 10% better than the one I have with minimal throttling due to heat generation.

Although I haven’t put mine through its paces with Final Cut Pro yet, there is, clearly, a question mark over its ability to act as a production machine for an ambitious creator.

Am I surprised? No, not at all. I’m still getting over the initial shock of an M1-based Mac making any form of noise, yes, but having thought about it a little more, it simply confirms the target market for this base level 24" iMac.

As noted in my review, it is perfect for families, hobbyists, general business use and anyone who wants to occasionally experiment with slightly more intensive computing tasks. It isn’t for people who undertake those tasks in order to make money. Those people should either spec-up their 24" iMac, opt for the M1 Mac mini, or wait for the big, pro-focused M-series iMac to hit the shelves.

I was going to hear the M1’s fan sooner or later, and I’m not in the least bit surprised that it happened on this particular Mac.

Before you go

Join my behind-the-scenes mailing list

Originally published at https://markellisreviews.com on June 14, 2021.

Technology
Mac
Apple
Computers
Tech
Recommended from ReadMedium