Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use sysbench

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use sysbench". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use sysbench.

For sysbench, a large number of lua templates are used, and lua templates are a necessary option for sysbench stress testing, so we need to better understand its implementation logic. If we can customize its implementation according to our own needs, to make it in line with the real business, this kind of benchmark test will be more meaningful. When you think of this, just do it.

We understand Lua from the perspective of sysbench and begin the learning journey of Lua.

When sysbench starts the test, the following information is displayed in the header:

Sysbench 1.1.0 (using bundled LuaJIT2.1.0-beta3)

This sentence has a lot of information, we can analyze it slowly, and we can clearly see that the Lua matched by sysbench is LuaJIT, which is a beta version. In this way, we need to confirm two points, one is that Lua calls the method of c, and LuaJIT is used here, so we should use the ffi library to call c, otherwise we usually use the Lua C API of c.

You can see the following confirmation of this information in the lua file based on sysbench.

Local ffi = require ("ffi")

Then the second question, at the system level, Lua is installed by default, which is basically version 5.1 or above, but we don't remember that LuaJIT has been installed. Did you install LuaJIT when you installed sysbench? We use find to simply verify that it is installed by default.

This is where the reference is the path that sysbench binds in the script and is not placed in the system-level environment variable. Calling c in LuaJIT is very smooth. For example, you can write a simple script, as follows:

This example refers to the network resources, and the execution result is as follows:

Then we can learn Lua systematically for a while, and then it will be much easier to look at the sysbench code after grasping the main points.

Let's start with the simplest Hello World.

> print ("Hello World!")

Hello World!

> print 'hello world'

Hello world

Reserved words in Lua have the following:

And break do else

Elseif end false for

Function if in local

Nil not or repeat

Return then true until

While

If you want to add comments, there are single lines and multiple lines, and multiple lines can be marked using-- [xxx -]].

>-- this is a test comment-- single-line comment

>-- [--Multiline comments

> > this is a test,line 1

> > this is a test comment line 2

> > this is a test comment line 3

>--]]

If the variable b is not assigned, it will be displayed as nil, and we can deal with the variable value in this way.

> print (b)

Nil

> bread10

Print b-- this naming is not up to standard

Stdin:1:'= 'expected near' b'

> print (b)

ten

And then it began to get difficult.

Let's take a look at the data types of learning routines. There are eight basic types in Lua: nil, boolean, number, string, userdata, function, thread and table.

To verify it is relatively easy, just use the type method.

> print (type ('hello world'))

String

> print (type (103.3))

Number

> print (type (print))

Function

> print (type (type))

Function

> print (type (nil))

Nil

> print (type (true))

Boolean

> print (type (type (x)

String

Ergodic tuple

If there is a key-value pair of data in this form, it can be returned by circular mapping. in the following two examples, the logic looks the same, but the final output is quite different.

> tab1 = {key1='val1',key2='val2','val3'}

> for KJE v in pairs (tab1) do

> > print (k.. "-" v)

> > end

1-val3

Key1-val1

Key2-val2

> tab1 = {key1='val1',key2='val2',key3='val3'}

> for KJE v in pairs (tab1) do

Print (k.. "-". V)

End

Key1-val1

Key3-val3

Key2-val2

With regard to type conversion, it is a common type of processing in programs, where numeric values are converted to characters, or characters are converted to numbers, which is not bad for Lua.

> print ("2" + 6)

eight

> print ('2' + 6)

eight

>

> print ("2" + "6")

eight

> print ("2x6")

2. 6.

> print ("- 2e2" * "6")

-1200

> print ("error" + 1)

Stdin:1: attempt to perform arithmetic on a string value

Stack traceback:

Stdin:1: in main chunk

[C]:?

>

> print ("a".. "b")

Ab

> print (123.. 456)

Stdin:1: malformed number near '123.. 456'

> print (123.. 456)

123456

If you want to calculate the length of a character, you can use the len method or variable method.

> len = "www.jeanron100.com"

> print (# len)

eighteen

> print (# "www.jeanron100.com")

eighteen

If you want to initialize table, you can use the following ways:

For example, declare such a table a, and then assign values to do data processing. The more important thing is to deal with the subscript. The subscript of Lua starts from 1.

> a = {}

> a ["key"] = "value"

> key=10

> a [key] = 100

> a [key] = a [key] + 1000

> for KJO v in pairs (a) do

> print (k.. ":" v)

> > end

Key:value

10:1100

If you want to strengthen the part of the loop, you can refer to the following example to loop out all the elements in fruits.

[root@oel641 lua] # cat test1.lua

Local fruits= {'apple','orange','banana'}

For key,val in pairs (fruits) do

Print ("key", key)

End

[root@oel641 lua] # lua test1.lua

Key 1

Key 2

Key 3

There are also functions in Lua that even support anonymous functions.

[root@oel641 lua] # cat test3.lua

Function factorial1 (n)

If n = = 0 then

Return 1

Else

Return n * factorial1 (nMel 1)

End

End

Print (factorial1 (5))

Factorial2=factorial1

Print (factorial2 (5))

This code is very similar to c, but the Lua is more interesting, and the function can be used more flexibly. It can be done directly through similar assignment methods. The output is as follows:

[root@oel641 lua] # lua test3.lua

one hundred and twenty

one hundred and twenty

At this point, I believe you have a deeper understanding of "how to use sysbench". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report